So I use :SetAsync() whenever a player leaves the game to save their wins, but I have been told that some players lose their stats. I looked into this and I’m trying to find a way to use :UpdateAsync() instead, but I don’t know how. Could anyone help me convert the code below to use :UpdateAsync()?
game.Players.PlayerAdded:Connect(function(Player)
local Leaderstats = Instance.new("Folder")
Leaderstats.Name = "leaderstats"
Leaderstats.Parent = Player
local Wins = Instance.new("IntValue")
Wins.Name = "Wins"
Wins.Value = 0
Wins.Parent = Leaderstats
local Data = DataStore:GetAsync(Player.UserId)
if Data then
Wins.Value = Data
end
end)
game.Players.PlayerRemoving:Connect(function(Player)
if game.PrivateServerId ~= "" then
print("Private server. Wins not saved.")
else
DataStore:SetAsync(Player.UserId, Player.leaderstats.Wins.Value)
end;
end);