DEAD AHEAD wins saving

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);

GlobalDataStore:UpdateAsync (roblox.com)

If you need more examples you should try searching for UpdateAsync in the search bar. Theres tons of results all over the devfourm.

Well I don’t know how to use Update Async but it might help to loop through all of the players every minute and save their data, that way you’re not relying only on the Player Removing function. You could add this code in at the bottom:

while wait(30) do   --how often it saves the data
       for i, player in pairs (game.Players:GetChildren()) do
          if game.PrivateServerId ~= "" then
		        print("Private server. Wins not saved.")
	      else
	        	DataStore:SetAsync(Player.UserId, Player.leaderstats.Wins.Value)
	      end
    end
end