# and getn returning 0 for a table with elements

I thought I was being trolled for the last half hour but no, its actually not working for me.

Did some research and either one of these should be returning the amount of elements in the table, but that is not the case here for some reason.

Both of those prints should be returning a value of 1, but in the screenshots below it is returning 0, both in Studio and in-game.

image
image

You can’t get the length of a dictionary using the # operator or table.getn().

Side note, table.getn() is deprecated.

AFAIK, the only way to get the length of a dictionary is to use a loop.

function getLengthOfDictionary(dict)
    local len = 0;
    for _, v in next, dict do
        len += 1;
    end
    return len;
end
2 Likes

thanks for the help, ive been awake too long to not realize this :sweat_smile:

1 Like