function Engine.CheckPlayerInventory()
	HotbarTable = {}
	for _,p in pairs (Hotbar:GetChildren()) do
		if p:IsA("Frame") then
			p:Destroy()
		end
	end
	for i,p in pairs (Player:WaitForChild("Backpack"):GetChildren()) do
		if #HotbarTable < HotbarLimit then
			table.insert(HotbarTable, p)
			local Slot = CreateSlot()
			Slot.SlotID.Text = i
			Slot.Button.Text = p.Name
			if i == 0 then
				i = 10
			end
			Slot.Name = "Slot".. i
			Slot.Parent = Hotbar
			Slot.Button.MouseButton1Click:connect(function()
				if p.Parent == Player.Character then
					Player.Character.Humanoid:UnequipTools()
					ResetHotBarColor()
				else
					Player.Character.Humanoid:UnequipTools()
					Player.Character.Humanoid:EquipTool(p)
					ResetHotBarColor()
					Hotbar["Slot".. i].BackgroundColor3 = Color3.new(20/255, 25/255, 30/255)
				end
			end)
			UserInputService.InputBegan:connect(function(Input)
				local KeyCode = Input.KeyCode
				if KeyCode == InventoryKeyCodes[i] and ToolsRestricted == false and ToolLocked == false then
					if p.Parent == Player.Character then
						Player.Character.Humanoid:UnequipTools()
						ResetHotBarColor()
					else
						Player.Character.Humanoid:UnequipTools()
						Player.Character.Humanoid:EquipTool(p)
						ResetHotBarColor()
						Hotbar["Slot".. i].BackgroundColor3 = Color3.new(20/255, 25/255, 30/255)
					end
				end
			end)
		end
	end
end
function Engine.ToggleHotbarVisibility(Visibility)
	Hotbar.Visible = Visibility
end
Player.Backpack.ChildAdded:connect(function(Child)
	Engine.CheckPlayerInventory()
end)
Player.Backpack.ChildRemoved:connect(function(Child)
	if Child.Parent ~= Player.Character then
		Engine.CheckPlayerInventory()
	end
end)

I made a custom inventory system that works. However there is a bug where if there are less than 2 tools in the inventory pressing the number keys won't equip it.

1 comment

0

That script looks good. Might not use it, but it does look legit. You should fix the bug