How to get the count of items in a table

Hello so i have a table of all the pets stored but I do not know how to find the exact number of items in the table is there a built-In-Function for it or something.Here is the script

local PetsFolder = game.Players.LocalPlayer:WaitForChild("PetsFolder")
local Inventory = game.Players.LocalPlayer.PlayerGui.Inventory
local ScrollingFrame = Inventory.LowerInvFrame.ScrollingFrame


while true do 
	wait(3)
for _, Pet in pairs(PetsFolder:GetChildren()) do
		
	-- see how much items in the petsfolder and for each pet make an instance and assign i 1 to the first image
	print(Pet.Name)
	
	end
end
1 Like

Using the # before a table would print the table’s count if the table is indexed

print(#PetsFolder:GetChildren())

3 Likes

You can use #PetsFolder:GetChildren() to get the exact number of items in the table

4 Likes

Use table.getn() to get the length of a table.

table.getn() or # is fine, for a dictionary you’d have to iterate over its contents.

local dict = {["a"] = 1, ["b"] = 2, ["c"] = 3}

local count = 0
for i, v in pairs(dict) do
	count += 1
end
print(count) --3
7 Likes

never knew you could do that, thanks.