Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

What is the problem with my datastore script , it doesn't save the stats?

Hello! I'm working on a game and i want to save the prestiges and points , but the datastore doesn't work... Can you guys help me?

My code :

    local DS = game:GetService("DataStoreService"):GetDataStore("SaveMyData")
    game.Players.PlayerAdded:Connect(function(plr)
wait()
local plrkey = "id_"..plr.userId
local savevalue = plr.leaderstats.Points
local savevalue2 = plr.leaderstats.Prestige
local savevalue3 = plr.Code


local GetSaved = DS:GetAsync(plrkey)
if GetSaved then
	savevalue.Value = GetSaved[1]
	savevalue2.Value = GetSaved[2]
	savevalue3.Value = GetSaved[3]
	
else
	local NumbersForSaving = {savevalue.Value, savevalue2.Value, savevalue3.Value}
	DS:GetAsync(plrkey, NumbersForSaving)
end
    end)

    game.Players.PlayerRemoving:Connect(function(plr)
DS:SetAsync("id_"..plr.userId, {plr.leaderstats.Points.Value, plr.leaderstats.Prestige.Value, 
    plr.Code.Value})
    end)

1 answer

✓ Accepted answer

The problem with Players.PlayerRemoving is that it doesn't save the last player in the server, the game will just shut down, regardless of any scripts running. To stop this from happening, you should be using game:BindToClose(). this function will run any function 30 seconds before the server shuts down.

1 comment

0

Thank you

This discussion is preserved as it was. New answers, comments, and votes are closed.