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