I have this script, and I want to load a saved table, and print it, and it won't work. Can anyone help?
local data = game:GetService("DataStoreService"):GetDataStore(plr.userId) local getdata = data:GetAsync("saves") local loaddata = {} for i, v in ipairs(getdata)do table.insert(loaddata, v) end print(table.concat(loaddata, ", "))
I wouldn't recommend using the players userId as a way to store data. Since it seems that you are only saving a table, it would be better to create a Datastore for everyone and save in accordance there. Also, if that is the full script, you never declared what 'plr' is. You're most likely saving it incorrectly.
The following is the way I'd recommend it:
local data = game:GetService("DataStoreService"):GetDataStore("arraySaves") game.Players.PlayerAdded:connect(function(p) local getdata = data:GetAsync(p.userId.."_saves") local loaddata = {unpack(getdata)} print(table.concat(loaddata, ", ")) end)
Of course, you'd have to change the way you are saving with the method above.
However, if you want to only see the solution to your problem, you aren't declaring plr.
game.Players.PlayerAdded:connect(function(p) local data = game:GetService("DataStoreService"):GetDataStore(p.userId) local getdata = data:GetAsync("saves") local loaddata = {unpack(getdata)} print(table.concat(loaddata, ", ")) end)