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

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

Asked by 4 years ago
Edited 4 years ago

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 :

01    local DS = game:GetService("DataStoreService"):GetDataStore("SaveMyData")
02    game.Players.PlayerAdded:Connect(function(plr)
03wait()
04local plrkey = "id_"..plr.userId
05local savevalue = plr.leaderstats.Points
06local savevalue2 = plr.leaderstats.Prestige
07local savevalue3 = plr.Code
08 
09 
10local GetSaved = DS:GetAsync(plrkey)
11if GetSaved then
12    savevalue.Value = GetSaved[1]
13    savevalue2.Value = GetSaved[2]
14    savevalue3.Value = GetSaved[3]
15 
View all 25 lines...

1 answer

Log in to vote
0
Answered by 4 years ago

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.

0
Thank you TheD4rkPow3r_WFE 13 — 4y
Ad

Answer this question