So, for my game, I want my leaderstats to save. I've tried datastores and whatnot, but nothing ever works. I then resorted to using a plain leaderstats save. I reused my old leaderstat save from another one of my old games, and it worked in that game, but it doesn't work for this new game... It's a normal script in serverscriptservice. I had to repost this since I wasn't getting any more responses. Code:
local CashStore = game:GetService("DataStoreService"):GetDataStore("DataStore")
function PlayerEntered(player)
repeat wait() until player.Character
local stats = Instance.new("IntValue")
stats.Parent = player
stats.Name = "leaderstats"
local cash = Instance.new("IntValue")
cash.Parent = stats
cash.Name = "Doubloons"
if CashStore:GetAsync("Points_"..player.UserID) ~= nil then
cash.Value = CashStore:GetAsync("Points_"..player.UserID)
else
cash.Value = 100
end
cash.Changed:connect(function(Val)
CashStore:SetAsync("Points_"..player.UserID, Val)
end)
game.Players.PlayerRemoved:Connect(function()
CashStore:SetAsync(player.UserID, cash.Value)
end)
end
game.Players.PlayerAdded:connect(PlayerEntered)
Thank you!

5 comments
Try moving lines 23-25 to the end of the script.
@TTChaos, Hi, thanks for responding! Unfortunately, that doesn't work.
See https://devforum.roblox.com/t/how-to-use-datastore2-data-store-caching-and-data-loss-prevention/136317 for datastore2
Delete line 4, https://devforum.roblox.com/t/avoiding-wait-and-why/244015
Can you send us a screenshot of you testing in studio