Hello, I am making a twitter codes system but I’m not sure how to check if the table is empty or not.
I am using table.find to check if something does not exist in the table, but if the table is empty it doesn’t work.
Hello, I am making a twitter codes system but I’m not sure how to check if the table is empty or not.
I am using table.find to check if something does not exist in the table, but if the table is empty it doesn’t work.
#{} prints zero(i.e. 0). Use the length operator, which is # and then compare it with the number 0.
However! Dictionaries cannot use length operators, which is truly a bummer. There’s probably a workaround with for instance next(dictionary) or pairs(dictionary).
It does not work and I am using dictionaries.
next(PlayersCodeData[player.UserId]) == nil
local empty = true
for k,v in pairs(tableRef) do empty = false break end
if empty then
print("table empty")
else
print("table not empty") end
replace tableRef with your table.
the easiest way to find if a table is emtpy is to do this.
if #tablename == 0 then
end
If it’s a list
if #t == 0 then
If it’s a dictionary
if next(t) == nil then
Since you’ve tried both, how about printing the table on the line above to ensure that it is in fact empty?