Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Help getting a table to load?

Asked by
Mr1Vgy 30
9 years ago

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, ", "))

1 answer

Log in to vote
2
Answered by 9 years ago

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)
1
Ok thanks, and sorry I forgot to put that this is inside a Player Added function, thanks for teaching me that there is a way to unpack a table! Mr1Vgy 30 — 9y
0
no prob anytime :D DigitalVeer 1473 — 9y
0
Can you put this as solved please. :) DigitalVeer 1473 — 9y
Ad

Answer this question