I change the value of Coins for ex. and it doesn't save next time I test the game
local DS = game:GetService("DataStoreService"):GetDataStore("ScriptingTestXOXOXO19191")--DO NOT CHANGE UNLESS YOU WANT EVERYONES STATS TO BECOME 0 AGAIN!
game.Players.PlayerAdded:Connect(function(plr)
local stats = Instance.new("Folder",plr)
stats.Name = "leaderstats"
local Coins = Instance.new("IntValue",stats)
Coins.Name = "Coins"
local Donuts = Instance.new("IntValue",stats)
Donuts.Name = "Donuts"
local Rebirths = Instance.new("IntValue",stats)
Rebirths.Name = "Rebirths"
local key = "player-"..plr.userId
local savedValues = DS:GetAsync(key)
if savedValues then
Coins.Value = savedValues[1]
Donuts.Value = savedValues[2]
Rebirths.Value = savedValues[3]
else
local valueToSave = {Coins.Value, Donuts.Value, Rebirths.Value}
DS:SetAsync(key, valueToSave)
end
end)
--Saving
game.Players.PlayerRemoving:Connect(function(plr)
local key = "player-"..plr.userId
local stat = plr.leaderstats
local valueToSave = {stat.Coins.Value, stat.Donuts.Value, stat.Rebirths.Value}
local success, err = pcall(function()
DS:SetAsync(key, valueToSave)
end)
if success then
print("Saving was successful")
else
error("Saving was not successful")
end
end)

3 comments
No loop or funcion. It will only save once when you join the game.
Ill rewrite the code for you Nvm its a free model XD Whats with that code
Wdym?