so im trying to script an inventory system whenever an item is added to the player’s inventory, it creates a gui frame for that item, which is shown in their backpack gui
however, the gui doesnt seem to update whenever an item is added
how do i fix this?
here is the code:
local function setUpInventory(player)
local inventory = player:WaitForChild("Inventory")
local playerGui = player:WaitForChild("PlayerGui")
local menuGui = playerGui:WaitForChild("MenuGui")
local backpackGui = menuGui:WaitForChild("BackpackMenuGui")
inventory.ChildAdded:Connect(function(item) --the child added is the item
print(item)
local itemGui = backpackGui.BackpackInventory.Templates.ItemFrame:Clone()
itemGui.Name = item.Name
itemGui.ItemName.Text = item.Name
itemGui.ItemAmount.Text = "x"..item.Value
if item.Value > 0 then
itemGui.Visible = true
itemGui.Parent = backpackGui.BackpackInventory.ItemList
else
itemGui.Visible = false
itemGui.Parent = backpackGui.BackpackInventory.ItemList
end
end)
end
game.Players.PlayerAdded:Connect(function(player)
local playerInventory = Instance.new("Folder")
playerInventory.Name = "Inventory"
playerInventory.Parent = player
setUpInventory(player)
end)
please help me
i am going insane