1 | table [ #table+ 1 ] = player.Name.. "=" ..ds:GetAsync(player.userId) or 0 |
2 |
3 | --attempt to concatenate a nil value |
I know it's erroring because I'm inserting a string and a number obviously which doesn't make sense for a normal table. I want to create a key and value inside of a dictionary..
The problem here is precedence.
or
is the lowest precedence, meaning the expression is interpreted as
1 | ( player.Name .. "=" .. ds:GetAsync(player.userId) ) or 0 |
You just need explicit parenthesis:
1 | player.Name .. "=" .. (ds:GetAsync(player.userId) or 0 ) |
The error should have hinted this -- it said you're concatenating nil
. Concatenating is the ..
operator; the only thing near a ..
that could be nil
is ds:GetAsync
.
Aside: This isn't a dictionary. This is a list.
You should consider using table.insert
instead of tab[#tab]
. You also really shouldn't use the variable name table
, because it will cover up the table
library and maybe mess you up later.