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

Why won't my data store save when I rejoin?

Asked by
CodeWon 181
3 years ago
Edited 3 years ago
local ds = game:GetService("DataStoreService"):GetDataStore("SaveData")
game.Players.PlayerAdded:Connect(function(plr)
    wait()
    local plrkey = "id_"..plr.userId
    local save1 = plr.leaderstats.Coins
    local save2 = plr.leaderstats.Level

    local GetSaved = ds:GetAsync(plrkey)
    if GetSaved then
        save1.Value = GetSaved[1]
        save2.Value = GetSaved[2]
    else
        local NumberForSaving = {save1.Value, save2.Value}
        ds:GetAsync(plrkey, NumberForSaving)
    end
end)

game.Players.PlayerRemoving:Connect(function(plr)
    ds:GetAsync("id_"..plr.userId, {plr.leaderstats.Coins.Value, plr.leaderstats.Level.Value})
end) 

I was using tutorials and going off of what I know when I was making a script. I was making a data store for leaderstats. My leaderstats where working okay, but data wasn't saving. I got no errors either. Could some please help?

0
could you put all the code into the code block valk_3D 140 — 3y
0
I dont know how to read it with the code everywher Galaxybombboy 134 — 3y
0
I definitely recommend using this https://www.youtube.com/watch?v=n1UpT2csAzo Galaxybombboy 134 — 3y
0
On line 7 i think you ment DS:SetAsync not GetAsync? MelodicSea5914 50 — 3y

Answer this question