I am trying to create an inventory system and I need to know if there is more than one of the same item in the inventory so the inventory can look functional and organized.
This is what I have tried so far:
inventoryEvent.OnClientEvent:Connect(function(ItemName)
local count = 0
for _,v in pairs(player.Inventory:GetChildren()) do
if v.Name == ItemName and count > 1 then
print("There is more than one.")
count = count + 1
end
end
But this does not work because every time inventoryEvent is fired then count will be set back to 0. So it seems I somehow need to make the script remember what the count was for the item.
I am thinking I can do that by adding a NumberValue under the item added to the inventory and changing the value each time a duplicate of the item is added to the inventory. But I still need the script be able to detect when there is more than one of the same item in the inventory.
How can I accomplish this?
