I have a Lua table:
local data = {
[player.UserId] = {
{
['sheet'] = 'playerdata', ['type'] = 'return', ['dataname'] = 'Money'
}
}
}
and somehow when I try to encode it into JSON… it throws an error of Invalid table key type used
.
I have a Lua table:
local data = {
[player.UserId] = {
{
['sheet'] = 'playerdata', ['type'] = 'return', ['dataname'] = 'Money'
}
}
}
and somehow when I try to encode it into JSON… it throws an error of Invalid table key type used
.
I couldn’t tell you precisely why this is the case, but it seems that this error gets fixed when you use a string for dictionary keys instead of integers. Try tostring(player.UserId)
Hmm, that’s strange. I just tried to use JSONEncode on your table, and it worked fine?
Are you sure that the player
variable is not nil?
player
is not nil since I’m getting it from PlayerAdded
event.