Hello fellow devforum users! I made a leaderstats script and would like it to save data, and it does. . . slightly. You see, it only saves the data if the data is added onto, but when I attempt to subtract from the data, it doesn’t save that.
Example: I earned 10 coins, it saves the coins value as 10 when I leave and rejoin. I spend 5 of the ten coins, it still saves as 10 when I leave and rejoin.
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder")
leaderstats.Name = ("leaderstats")
leaderstats.Parent = plr
local cash = Instance.new("IntValue")
cash.Name = "Coins"
cash.Parent = leaderstats
cash.Value = 0
cash.Value = CashData:GetAsync(plr.UserId) or Value
CashData:SetAsync(plr.UserId, cash.Value)
game.Players.PlayerRemoving:Connect(function(plr)
CashData:SetAsync(plr.UserId, plr.leaderstats.Coins.Value)
end)
end)