Length of Table is Printed Incorrectly

Hi Everyone,
For some reason, I’m getting the wrong length of the table in my code. It’s displaying it as zero which is confusing me a lot.

In this case, in the screenshots I provided I playtest with two players and the game is still printing the wrong table length which is breaking my code.

Maybe I do not understand why it’s doing so, and it is my fault, if so please let me know. In my code I print the table, then the length, then again the entire table just to show that nothing has changed with the table.

Any advice would be appreciated.

for i, player in pairs(Players) do
	playerInObby[player.Name] = true
end

for playerName, value in pairs(playerInObby) do
	print(playerName..":",value)
end
print(playerInObby)
print(#playerInObby)
print(playerInObby)

The table is declared at the start of my script like this:

local playerInObby = {}

Screenshot of output:
bug2

It only works if the keys aka the players here are index like 1 ,2 …ect it doesnt work with other keys excpet for indexexs . In short it only works with arrays

The # operator cannot quantify dictionaries, you have to find another way to get the count of values inside a dictionary.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.