-
What do you want to achieve?
I’m working on a custom inventory system. -
What is the issue?
It doesn’t seem to update whenever I pick up or drop a tool. -
What solutions have you tried so far?
This is my code
function updateInv()
print'update aaaaaaaaa rofls' -- Purely for scientific purposes
BackpackFrame:ClearAllChildren() -- removes previous buttons
script.InvLayout:Clone().Parent = BackpackFrame- -- adds a GuiGridLayout
local tools = Player.Backpack:GetChildren() -- Gets all the tools
tools[#tools+1] = Char:FindFirstChildOfClass('Tool') -- Gets the tools inside the character
for i,v in pairs(tools) do -- for all these tools
if v:IsA('Tool') then -- if it really is a tool
local item = script.BackpackItem:Clone() -- create a button for it
item.Parent = BackpackFrame -- parent the button to the frame
item.ImageLabel.Image = v.TextureId -- give the button the tool's image
end
end
end
updateInv()
Player:WaitForChild('Backpack') -- wait for the backpack
Player.Backpack.ChildAdded:connect(updateInv) -- call this function every time something is added to the backpack
Player.Backpack.ChildRemoved:connect(updateInv) -- call this function every time something is removed from the backpack
Player.Backpack.DescendantAdded:connect(updateInv) -- aaaaaaaaa
Player.Backpack.DescendantRemoving:connect(updateInv) -- imgettingdesperate
y it no update?
i no understand
I’m probably doing something really stupid or something.
Can someone enlighten me?
EDITS:
Commented code so it’s easier to understand
Reduced a thingy so it’s one line for better readability