Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local DataStoreService = game:GetService("DataStoreService")
- local Players = game:GetService("Players")
- local StatsStore = DataStoreService:GetDataStore("StatsStore")
- Players.PlayerAdded:Connect(function(Player)
- local Leaderstats = Instance.new("Folder", Player)
- Leaderstats.Name = "leaderstats"
- local Points = Instance.new("NumberValue", Leaderstats)
- Points.Name = "Points"
- local Wins = Instance.new("IntValue", Leaderstats)
- Wins.Name = "Wins"
- local Rank = Instance.new("StringValue", Leaderstats)
- Rank.Name = "Rank"
- local Data = StatsStore:GetAsync(Player.UserId)
- if Data then
- Points.Value = Data.Points or Data[1]
- Wins.Value = Data.Wins or Data[2]
- Rank.Value = Data.Rank or Data[3]
- elseif not Data then
- Points.Value = 0
- Wins.Value = 0
- Rank.Value = "Unranked"
- end
- end)
- Players.PlayerRemoving:Connect(function(Player)
- local Leaderstats = Player:FindFirstChild("leaderstats")
- if Leaderstats then
- local Points = Leaderstats:WaitForChild("Points")
- local Wins = Leaderstats:WaitForChild("Wins")
- local Rank = Leaderstats:WaitForChild("Rank")
- StatsStore:SetAsync(Player.UserId, {
- Points = Points.Value,
- Wins = Wins.Value,
- Rank = Rank.Value,
- })
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement