Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local TeleportService = game:GetService("TeleportService")
- local WinsDataStore = game:GetService("DataStoreService"):GetDataStore("Wins")
- local RoundsDataStore = game:GetService("DataStoreService"):GetDataStore("Rounds")
- game.Players.PlayerAdded:Connect(function(player)
- local previousData = WinsDataStore:GetAsync(player.UserId) -- Returns a number value.
- local previousData2 = RoundsDataStore:GetAsync(player.UserId)
- local leaderstats = Instance.new("Folder", player)
- leaderstats.Name = "leaderstats"
- local Wins
- local Rounds
- if previousData ~= nil then
- Wins = previousData
- else
- Wins = 0
- WinsDataStore:SetAsync(player.UserId, 0)
- end
- local coinsValue = Instance.new("NumberValue", leaderstats)
- coinsValue.Name = "Wins"
- coinsValue.Value = Wins
- if previousData2 ~= nil then
- Rounds = previousData2
- else
- Rounds = 0
- RoundsDataStore:SetAsync(player.UserId, 0)
- end
- local coinsValue = Instance.new("NumberValue", leaderstats)
- coinsValue.Name = "Rounds"
- coinsValue.Value = Rounds
- end)
- game:BindToClose(function() -- Runs whenver the server is about to shut down/stop.
- print("STOPPED!")
- for i,player in pairs(game.Players:GetPlayers()) do
- local value = player.leaderstats.Wins.Value
- local value2 = player.leaderstats.Rounds.Value
- WinsDataStore:SetAsync(player.UserId, value)
- RoundsDataStore:SetAsync(player.UserId, value2)
- print("Saved data for "..player.Name)
- end
- end)
- game.Players.PlayerRemoving:Connect(function(player)
- local value = player.leaderstats.Wins.Value
- local value2 = player.leaderstats.Rounds.Value
- if value ~= nil then
- print("Found data to save for "..player.Name.."!")
- WinsDataStore:SetAsync(player.UserId, value)
- RoundsDataStore:SetAsync(player.UserId, value2)
- print("Saved data for "..player.Name)
- else
- print("Did not manage to find data to save for "..player.Name.."!")
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment