I'm trying to save some values to a datastore, however you can't save dictionaries. I have one below as an example:
{ ["Money"] = 0, ["Cars"] = "One, two, three", ["DistanceWalked"] = 16 }
EDIT: This is the code I'm using - The SaveOther folder contains about 6 values, the name of all of them are strings, but the values themselves are integers AND strings.
local datastore = game:GetService("DataStoreService") while true do wait (30) print ("lets go") local players = game.Players:GetChildren() for i=1, #players do local player = players[i] local cardata = player.PlayerData local playerstats = datastore:GetDataStore("TempStats") --cardata = playerstats:SetAsync(player.UserId.."_Stats",cardata) local values = cardata.SaveOther:GetChildren() local mytable = {} for a=1, #values do mytable[values[a]] = values[a].Value print (mytable[values[a]]) end print(mytable) local testtable = {} testtable[1] = mytable print(tostring(player.UserId.."_Stats2")) local key = tostring(player.UserId.."_Stats2") playerstats:SetAsync(key, testtable) end end
I get the "09:50:24.466 - keys must be strings" error, although I can't understand why they're not strings.
values
is a table of objects, returned by GetChildren()
from line 11.
When you do mytable[values[a]]
on line 14, your setting the keys of mytable
to an object. As you may already know, the keys of tables uploaded to a datastore cannot be objects.
I think you meant to do mytable[a]
on line 14. This should fix your problem.