function handleEquip(E)if E then if E.Parent~=char then hum:EquipTool(E)else hum:UnequipTools()end end end function create()local E=#inputOrder local l=E*iconSize.X.Offset+(E+1)*iconBorder.x local i=iconSize.Y.Offset+2*iconBorder.y frame.Size=UDim2.new(0,l,0,i)frame.Position=UDim2.new(.5,-(l/2),1,-(i+iconBorder.y*2))frame.Visible=true for E=1,#inputOrder,1 do local l=inputOrder[E]local i=template:Clone()i.Parent=frame i.Label.Text=l.txt i.Name=l.txt i.Visible=true i.Position=UDim2.new(0,(E-1)*iconSize.X.Offset+iconBorder.x*E,0,iconBorder.y)i.ImageTransparency=unequipped local h=l.tool if h then i.Tool.Image=h.TextureId end i.Tool.MouseButton1Down:Connect(function()for E,l in pairs(inputKeys)do if l.txt==i.Name then handleEquip(l.tool)end end end)end template:Destroy()end function setup()local E=bp:GetChildren()for l=1,#E,1 do for l=1,#inputOrder,1 do local i=inputOrder[l]if not i.tool then i.tool=E[l]break end end end create()end function adjust()for E,l in pairs(inputKeys)do local i=l.tool local h=frame:FindFirstChild(l.txt)if i then h.Tool.Image=i.TextureId if i.Parent==char then h.ImageTransparency=equipped else h.ImageTransparency=unequipped end else h.Tool.Image=""h.ImageTransparency=unequipped end end end function onKeyPress(E)local l=E.KeyCode.Name local i=inputKeys[l]if i and uis:GetFocusedTextBox()==nil then handleEquip(i.tool)end end function handleAddition(E)if E:IsA("\084\111\111\108")then local l=true for i,h in pairs(inputKeys)do local q=h.tool if q then if q==E then l=false end end end if l then for l=1,#inputOrder,1 do local i=inputOrder[l].tool if not i then inputOrder[l].tool=E break end end end adjust()end end function handleRemoval(E)if E:IsA("\084\111\111\108")then if E.Parent~=char and E.Parent~=bp then for l=1,#inputOrder,1 do if inputOrder[l].tool==E then inputOrder[l].tool=nil break end end end adjust()end end uis.InputBegan:Connect(onKeyPress)char.ChildAdded:Connect(handleAddition)char.ChildRemoved:Connect(handleRemoval)bp.ChildAdded:Connect(handleAddition)bp.ChildRemoved:Connect(handleRemoval)setup()

function handleEquip(tool)
	if tool then
		if tool.Parent ~= char then
			hum:EquipTool(tool)
		else
			hum:UnequipTools()
		end
	end
end

function create()

	local toShow = #inputOrder
	local totalX = (toShow*iconSize.X.Offset)+((toShow+1)*iconBorder.x)
	local totalY = iconSize.Y.Offset + (2*iconBorder.y)
	
	frame.Size = UDim2.new(0, totalX, 0, totalY)
	frame.Position = UDim2.new(0.5, -(totalX/2), 1, -(totalY+(iconBorder.y*2)))
	frame.Visible = true

	for i = 1, #inputOrder do
		
		local value = inputOrder[i]		
		local clone = template:Clone()
		clone.Parent = frame
		clone.Label.Text = value["txt"]
		clone.Name = value["txt"]
		clone.Visible = true
		clone.Position = UDim2.new(0, (i-1)*(iconSize.X.Offset)+(iconBorder.x*i), 0, iconBorder.y)
		clone.ImageTransparency = unequipped

		local tool = value["tool"]
		if tool then
			clone.Tool.Image = tool.TextureId
		end

		clone.Tool.MouseButton1Down:Connect(function()
			for key, value in pairs(inputKeys) do
				if value["txt"] == clone.Name then
					handleEquip(value["tool"]) 
				end 
			end
		end)

	end	
	template:Destroy()
end

function setup()
	local tools = bp:GetChildren()
	for i = 1, #tools do
		for i = 1, #inputOrder do
			local value = inputOrder[i]
			if not value["tool"] then
				value["tool"] = tools[i]	
				break
			end
		end
	end
	create()
end

function adjust()
	for key, value in pairs(inputKeys) do
		local tool = value["tool"]
		local icon = frame:FindFirstChild(value["txt"])
		if tool then
			icon.Tool.Image = tool.TextureId
			if tool.Parent == char then
				icon.ImageTransparency = equipped
			else
				icon.ImageTransparency = unequipped
			end
		else
			icon.Tool.Image = ""
			icon.ImageTransparency = unequipped
		end
	end
end

function onKeyPress(inputObject)
	local key = inputObject.KeyCode.Name
	local value = inputKeys[key]
	if value and uis:GetFocusedTextBox() == nil then
		handleEquip(value["tool"])
	end 
end

function handleAddition(adding)

	if adding:IsA("Tool") then
		local new = true

		for key, value in pairs(inputKeys) do
			local tool = value["tool"]
			if tool then
				if tool == adding then
					new = false
				end
			end
		end

		if new then
			for i = 1, #inputOrder do
				local tool = inputOrder[i]["tool"]
				if not tool then
					inputOrder[i]["tool"] = adding
					break
				end
			end
		end

	adjust()
	end
end

function handleRemoval(removing) 
	if removing:IsA("Tool") then
		if removing.Parent ~= char and removing.Parent ~= bp then

			for i = 1, #inputOrder do
				if inputOrder[i]["tool"] == removing then
					inputOrder[i]["tool"] = nil
					break
				end
			end
		end

		adjust()
	end
end

uis.InputBegan:Connect(onKeyPress) --keyinput 

char.ChildAdded:Connect(handleAddition)
char.ChildRemoved:Connect(handleRemoval)

bp.ChildAdded:Connect(handleAddition)
bp.ChildRemoved:Connect(handleRemoval)

setup()
