Why does table.find() buggy?

I was trying to check if there is a value on that table using table.find() but it didn’t work well…

print(table.find(classedPlayers, classedPlayers[plr.Name]))

And this is what the output give me, I seriously have no idea on why is that a nil value.


but isn’t the 2nd argument suppose to be a value, and it will return the index value of that value?

You’re using it incorrectly, the value you’re passing to table.find is nil, for just one player, you meant to do

print(table.find(classedPlayers, classedPlayers[1]))

Although this is extremely unnecessary as you should just use the player’s name, the above is totally useless but just correctly does what could be implied through your code (just for some reason print the index??) .

so how can I use it properly? (30 characters)

I just want to know if the value is inside the table for an if statement.

Could I use classedPlayers[plr.Name] instead of using table.find?

if table.find(classedPlayers,plr.Name) then

1st argument is where the find should start, 2nd argument if the value.

Yes I did, but however, it always give me nil eventhough the value is inside.

I tried to use plr, plr.Name both of them, none works

Don’t do classedPlayers[plr] nor classedPlayers[plr.Name]. Do table.find(classedPlayers,plr.Name).

1 Like

yes im dumb, wow I didn’t even think of that, thanks

1 Like