Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local TeleportService = game:GetService("TeleportService")
- local players = game:GetService('Players')
- local dataStoreService = game:GetService('DataStoreService')
- local saveDataStore = dataStoreService:GetDataStore("SaveData")
- players.PlayerAdded:Connect(function(plr)
- local stats = Instance.new('Folder')
- stats.Name = 'leaderstats'
- stats.Parent = plr
- local Wins = Instance.new('IntValue')
- Wins.Name = 'Wins'
- Wins.Parent = stats
- local data = saveDataStore:GetAsync(plr.UserId)
- if data then
- for name, value in pairs(data.Stats) do
- stats[name].Value = value
- end
- end
- end)
- players.PlayerRemoving:Connect(function(plr)
- local saveData = {Stats = {}}
- for _,stat in pairs(plr.leaderstats:GetChildren()) do
- saveData.Stats[stat.Name] = stat.Value
- end
- saveDataStore:SetAsync(plr.UserId,saveData)
- end)
- game:BindToClose(function()
- for _,plr in pairs(players:GetChildren()) do
- local saveData = {Stats = {}}
- for _,stat in pairs(plr.leaderstats:GetChildren()) do
- saveData.Stats[stat.Name] = stat.Value
- end
- saveDataStore:SetAsync(plr.UserId, saveData)
- end
- wait(2)
- end)
Advertisement
Add Comment
Please, Sign In to add comment