local Item = script.Parent.Item
local Inv = script.Parent.Inventory
local BackPack = script.Parent.Parent.Parent:WaitForChild("Backpack")
local ItemNumber = 1
local RBXConnections = {
}
local function EquipTool(Number)
print("Equipping: ", Number)
if Inv:FindFirstChild(tostring(Number)) then
local CloneTool : Tool = Inv:FindFirstChild(tostring(Number)).Refrence.Value:Clone()
CloneTool.Parent = game.Workspace
local Humanoid : Humanoid = game.Players.LocalPlayer.Character.Humanoid
Humanoid:EquipTool(CloneTool)
CloneTool.Unequipped:Connect(function()
CloneTool:Destroy()
end)
end
end
local function MakeItem(ItemInfo)
if ItemNumber > 9 then
warn("Ran out of space.")
return
end
local Clone = Item:Clone()
Clone.Parent = script.Parent.Inventory
Clone.Refrence.Value = ItemInfo.Object
if game.ReplicatedStorage.WeaponDatas:FindFirstChild(Clone.Refrence.Value.Name) then
local Require = require(game.ReplicatedStorage.WeaponDatas:FindFirstChild(Clone.Refrence.Value.Name))
if string.find(Require.WeaponInfo.WeaponName, "rbxassetid://") then
Clone.ItemName.Text = ""
Clone.Click.Image = Require.WeaponInfo.WeaponName
else
Clone.ItemName.Text = Require.WeaponInfo.WeaponName
end
else
Clone.ItemName.Text = ItemInfo.Object.Name
end
Clone.ItemNumber.Text = tostring(ItemNumber)
Clone.Name = tostring(ItemNumber)
Clone.Visible = true
local Connection = Clone.Click.MouseButton1Click:Connect(function()
EquipTool(tonumber(Clone.ItemNumber.Text))
end)
table.insert(RBXConnections, Connection)
ItemNumber += 1
end
local function ClearHotbar()
table.clear(RBXConnections)
ItemNumber = 1
for _, V in Inv:GetChildren() do
if V:IsA("Frame") then
V:Destroy()
end
end
end
local function UpdateHotbar()
ClearHotbar()
for _, V in BackPack:GetChildren() do
MakeItem({Object = V})
end
end
UpdateHotbar()
local UIS = game.UserInputService
UIS.InputBegan:Connect(function(Inp, GPE)
if Inp.KeyCode == Enum.KeyCode.One then
EquipTool(1)
elseif Inp.KeyCode == Enum.KeyCode.Two then
EquipTool(2)
elseif Inp.KeyCode == Enum.KeyCode.Three then
EquipTool(3)
elseif Inp.KeyCode == Enum.KeyCode.Four then
EquipTool(4)
elseif Inp.KeyCode == Enum.KeyCode.Five then
EquipTool(5)
elseif Inp.KeyCode == Enum.KeyCode.Six then
EquipTool(6)
elseif Inp.KeyCode == Enum.KeyCode.Seven then
EquipTool(7)
elseif Inp.KeyCode == Enum.KeyCode.Eight then
EquipTool(8)
elseif Inp.KeyCode == Enum.KeyCode.Nine then
EquipTool(9)
end
end)
BackPack.ChildAdded:Connect(UpdateHotbar)
BackPack.ChildRemoved:Connect(UpdateHotbar)
I cant get this system working properly, it loads all the items, it detects when you click or use a number key, but it wont equip the tools. It just puts them in workspace and they fall through the map.
I know what im doing in not very good, but i have no idea how to make a custom inventory, and all the toolbox ones dont fit what i need, or fix the issues with the old system.
I just want an inventory system with tooltips, proper numbering, and a accessible backpack with “~”.