The for loop is iterating through a table with tables inside it. I’m trying to catch the tables that aren’t empty with #v, but even though it iterated over a table that had more than 0 elements in it, it still printed as 0. Why is this?
Code
game.ReplicatedStorage.Inventory.MapInventory.OnClientEvent:Connect(function(Inventory)
for i,v in pairs(Inventory.Data) do
print(v)
print(#v)
end
end)
Output
Table has [“Bucket”] = 1, but after it still prints 0.
Thank you for this. This is the final code I got to work
game.ReplicatedStorage.Inventory.MapInventory.OnClientEvent:Connect(function(Inventory)
for i,v in pairs(Inventory.Data) do
for a,b in pairs(v) do
if b then
print(v)
end
end
end
end)