I also wanted to let you that that FE is on and the script is in the workspace
local DSService = game:GetService("DataStoreService"):GetDataStore("Currency") game:GetService("Players").PlayerAdded:connect(function(plr) local leader = Instance.new("Folder",plr) leader.Name = "leaderstats" local Credits = Instance.new("IntValue",leader) Credits.Name = "Credits" local Diamonds = Instance.new("IntValue",leader) Diamonds.Name = "Diamonds" local savedData = DSService:GetAsync(plr.UserId.."-Currency") if savedData then Credits.Value = savedData[1] Diamonds.Value = savedData[2] else local values = {Credits.Value, Diamonds.Value} DSService:SetAsync(plr.UserId.."-Currency",values) end end) game:GetService("Players").PlayerRemoving:connect(function(plr) local ValuesToSave = {plr.leaderstats.Credits.Value, plr.leaderstats.Diamonds.Value} DSService:SetAsync(plr.UserId.."-Currency", ValuesToSave) end) while wait(300) do for i,v in pairs(game:GetService("Players"):GetChildren()) do DSService:UpdateAsync(v.UserId,v.leaderstats.Credits.Value,v.leaderstats.Diamonds.Value) end end
The server is shutting down before the data saves. To prevent this, you need to add game:BindToClose() to the script. Try this instead
local DSService = game:GetService("DataStoreService"):GetDataStore("Currency") local Saving = 0 game:BindToClose(function() repeat wait() until Saving <= 0 end) game:GetService("Players").PlayerAdded:connect(function(plr) local leader = Instance.new("Folder",plr) leader.Name = "leaderstats" local Credits = Instance.new("IntValue",leader) Credits.Name = "Credits" local Diamonds = Instance.new("IntValue",leader) Diamonds.Name = "Diamonds" local savedData = DSService:GetAsync(plr.UserId.."-Currency") if savedData then Credits.Value = savedData[1] Diamonds.Value = savedData[2] else local values = {Credits.Value, Diamonds.Value} DSService:SetAsync(plr.UserId.."-Currency",values) end end) game:GetService("Players").PlayerRemoving:connect(function(plr) Saving = Saving + 1 local ValuesToSave = {plr.leaderstats.Credits.Value, plr.leaderstats.Diamonds.Value} DSService:SetAsync(plr.UserId.."-Currency", ValuesToSave) Saving = Saving - 1 end) while wait(300) do for i,v in pairs(game:GetService("Players"):GetChildren()) do DSService:UpdateAsync(v.UserId,v.leaderstats.Credits.Value,v.leaderstats.Diamonds.Value) end end