The server is shutting down before the data saves. To prevent this, you need to add game:BindToClose() to the script. Try this instead
01 | local DSService = game:GetService( "DataStoreService" ):GetDataStore( "Currency" ) |
04 | game:BindToClose( function () |
05 | repeat wait() until Saving < = 0 |
08 | game:GetService( "Players" ).PlayerAdded:connect( function (plr) |
09 | local leader = Instance.new( "Folder" ,plr) |
10 | leader.Name = "leaderstats" |
12 | local Credits = Instance.new( "IntValue" ,leader) |
13 | Credits.Name = "Credits" |
15 | local Diamonds = Instance.new( "IntValue" ,leader) |
16 | Diamonds.Name = "Diamonds" |
18 | local savedData = DSService:GetAsync(plr.UserId.. "-Currency" ) |
21 | Credits.Value = savedData [ 1 ] |
22 | Diamonds.Value = savedData [ 2 ] |
24 | local values = { Credits.Value, Diamonds.Value } |
25 | DSService:SetAsync(plr.UserId.. "-Currency" ,values) |
29 | game:GetService( "Players" ).PlayerRemoving:connect( function (plr) |
31 | local ValuesToSave = { plr.leaderstats.Credits.Value, plr.leaderstats.Diamonds.Value } |
32 | DSService:SetAsync(plr.UserId.. "-Currency" , ValuesToSave) |
37 | for i,v in pairs (game:GetService( "Players" ):GetChildren()) do |
38 | DSService:UpdateAsync(v.UserId,v.leaderstats.Credits.Value,v.leaderstats.Diamonds.Value) |