the text prints every time and the leader stats show, but it never saves.
local DS = game:GetService("DataStoreService"):GetDataStore("storage")
game.Players.PlayerAdded:Connect(function(plr)
local stats = Instance.new("Folder")
stats.Name = "leaderstats"
stats.Parent = plr
local Soul = Instance.new("IntValue")
Soul.Name = "Cash"
Soul.Parent = stats
Soul.Value = DS:GetAsync(plr.UserId) or 0
DS:SetAsync(plr.UserId,Soul.Value)
Soul.Changed:Connect(function()
print("saving")
DS:SetAsync(plr.UserId,Soul.Value)
print("finished saving")
end)
end)
game.Players.PlayerRemoving:Connect(function(plr)
print("saving data")
DS:SetAsync(plr.UserId,plr.leaderstats.Cash.Value)
print(plr.Name.."'s scream data has been saved")
end)
sorry about the code for some reason scripting helpers spaces it out when i paste it

3 comments
This happened to me, I solved it by using bind to close as well as player removing. It’s because every time u test it the place shuts down before the player removing can save it
in studio you are probably pressing the "stop" button, which will only work if you have BindToClose(), PlayerRemoving is when you press escape, L, and leave the game how it is suppose to be done.
Are you also sure that you have Studio Access to API Services enabled? I was able to paste this into a blank place and it worked fine for me. Are you also sure that when you edit the data it's done server side? If you try to alter it from the client it will not save information that's not present on the server.