Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Players = game:GetService('Players')
- local DatastoreService = game:GetService("DataStoreService")
- local TeleportService = game:GetService("TeleportService")
- local dVersion = 1
- local WinsDataStore = DatastoreService:GetDataStore('Wins')
- Players.PlayerAdded:Connect(function(Player)
- local Stats = Instance.new('Folder')
- Stats.Name = 'leaderstats'
- Stats.Parent = Player
- local Wins = Instance.new('IntValue')
- Wins.Name = 'Wins'
- Wins.Parent = Stats
- local Data = WinsDataStore:GetAsync(Player.UserId)
- if Data then
- for name, value in pairs(Data.Stats) do
- Stats[name].Value = value
- end
- end
- end)
- Players.PlayerRemoving:Connect(function(Player)
- local SaveData = {Stats = {}}
- for _, stat in pairs(Player.leaderstats:GetChildren()) do
- SaveData.Stats[stat.Name] = stat.Value
- end
- WinsDataStore:SetAsync(Player.UserId,SaveData)
- end)
- game:BindToClose(function()
- for _, Player in pairs(game.Players:GetPlayers()) do
- local SaveData = {Stats = {}}
- for _,stat in pairs(Player.leaderstats:GetChildren()) do
- SaveData.Stats[stat.Name] = stat.Value
- end
- WinsDataStore:SetAsync(Player.UserId,SaveData)
- end
- wait(2)
- end)
- local save2 = DatastoreService:GetOrderedDataStore("Rounds "..dVersion)
- game.Players.PlayerAdded:Connect(function(player)
- local previousData = save2:GetAsync(player.UserId) -- Returns a number value.
- local Rounds
- if previousData ~= nil then
- Rounds = previousData
- else
- Rounds = 0
- save2:SetAsync(player.UserId, 0)
- end
- local coinsValue = Instance.new("IntValue", player)
- 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.Rounds.Value
- save2:SetAsync(player.UserId, value)
- print("Saved data for "..player.Name)
- end
- end)
- game.Players.PlayerRemoving:Connect(function(player)
- local value = player.Rounds.Value
- if value ~= nil then
- print("Found data to save for "..player.Name.."!")
- save2: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)
- local teleportData = TeleportService:GetLocalPlayerTeleportData()
- if teleportData then
- local Player = game.Players:GetPlayerByUserId(teleportData.PlayerName)
- Player:WaitForChild('leaderstats'):WaitForChild('Wins').Value = Player.leaderstats.Wins.Value + 1
- end
Add Comment
Please, Sign In to add comment