Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to check if a table has any values in it?

Asked by
stepatron 103
5 years ago

I have this script that basically has a table with user id's for y'know, admins. the table is empty with no values so when I try to execute any code with it, it glitches and returns the wrong value, ex: true instead of false. Is there a way to check if a table has any values in it?

1 answer

Log in to vote
1
Answered by
Avigant 2374 Moderation Voter Community Moderator
5 years ago

To check if a table has a key value pair, we can simply use the next() function, like so:

local EmptyTable = {}

if next(EmptyTable) then
    print("There's a key-value pair!")
else
    print("There's not a key-value pair!")
end
Ad

Answer this question