Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I determine the size of a table?

Hi guys,

I have a table with ~150 items in it and I was wondering how I can count the number of entries within the table?

Am I being dumb and using print(#items) wrong? or does that only work for arrays?

I've also tried:

NoCreatures = function()
	local count = 0

	for _ in pairs (items) do 
		count = count + 1
	end
	
	print(count)
end

I'm sure there's a simple solution to this one! haha

Thanks for your time :)

1 answer

✓ Accepted answer

Arrays are tables with a number as the key in Lua so #array should work.

4 comments

0

Does it matter that I have made it like --> Items["#092"]="Example" ?

0

Items = {} is at the beggining of it all. and I know it looks stupid to have it as #000 instead of just letting it be an array but there's a reason haha (e.g. the final number, #150 is only about number 146)

0

Not at all since "#092" is being treated as a key. Though you can't iterate through it with numbers unless you do something semicomplex..

0

Thanks for the help :)

This discussion is preserved as it was. New answers, comments, and votes are closed.