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) |
03 | wait() |
04 | local plrkey = "id_" ..plr.userId |
05 | local savevalue = plr.leaderstats.Points |
06 | local savevalue 2 = plr.leaderstats.Prestige |
07 | local savevalue 3 = plr.Code |
08 |
09 |
10 | local GetSaved = DS:GetAsync(plrkey) |
11 | if GetSaved then |
12 | savevalue.Value = GetSaved [ 1 ] |
13 | savevalue 2. Value = GetSaved [ 2 ] |
14 | savevalue 3. Value = GetSaved [ 3 ] |
15 |
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.