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

my leaderstats datastore isnt working.. how do i fix it?

Asked by
CMB1048 25
1 year ago
Edited 1 year ago

my data doesnt save when i rejoin

this is in a seperate script from the leaderstats

local datastore = game:GetService("DataStoreService"):GetDataStore("SavaData")
game.Players.PlayerAdded:Connect(function(plr)
    wait()
    local plrid = "id_"..plr.UserId
    local save1 = plr.leaderstats.Coins

    local GetSaved = datastore:GetAsync(plrid)
    if GetSaved then
        save1.Value = GetSaved[1]

    else
        local NumberForSaving = {save1.Value}
        datastore:GetAsync(plrid, NumberForSaving)

    end
end)

game.Players.PlayerRemoving:Connect(function(plr)
    datastore:SetAsync("id_"..plr.UserId{plr.leaderstats.Coins.Value})
end)
0
anyone helping me out? its been 11 hours and i need this bad CMB1048 25 — 1y

1 answer

Log in to vote
0
Answered by 1 year ago

I believe that your data isn't saving because the server shuts down before SetAsync() can be called (assuming you are the only person testing). Try using game:BindToClose() so that the server gives itself time to save everything before it shuts down completely.

For example:

game:BindToClose(function()
    --here you would loop through all players and save their data
end)
Ad

Answer this question