local TeleportService = game:GetService("TeleportService")
local dVersion = 1
local SaveWins = game:GetService("DataStoreService"):GetOrderedDataStore("Wins", dVersion)
game.Players.PlayerAdded:Connect(function(player)
local previousData = SaveWins:GetAsync(player.UserId)
local Wins
if previousData ~= nil then
Wins = previousData
else
Wins = 0
SaveWins:SetAsync(player.UserId, 0)
end
local WinsValue = Instance.new("NumberValue", player)
WinsValue.Name = "Wins"
WinsValue.Value = Wins
end)
game:BindToClose(function()
for i, player in pairs(game.Players:GetPlayers()) do
local Value = player.Wins.Value
SaveWins:SetAsync(player.UserId, Value)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local Value = player.Wins.Value
if Value ~= nil then
print("Found data to save for "..player.Name.."!")
SaveWins:SetAsync(player.UserId, Value)
print("Saved data for "..player.Name)
else
print("Did not manage to find data to save for "..player.Name.."!")
end
end)