Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Players = game:GetService("Players")
- local DataStoreService = game:GetService("DataStoreService")
- local DataStore = DataStoreService:GetDataStore("MyDataStore")
- local function PlayerAdded(Player: Player)
- local Leaderstats = Instance.new("Folder", Player)
- Leaderstats.Name = "leaderstats"
- local Rings = Instance.new("NumberValue", Leaderstats)
- Rings.Name = "Rings"
- Rings.Value = 1
- local Level = Instance.new("NumberValue", Leaderstats)
- Level.Name = "Level"
- Level.Value = 1
- local XP = Instance.new("NumberValue", Player)
- XP.Name = "XP"
- XP.Value = 1
- local Success, SavedData = pcall(function()
- return DataStore:GetAsync(Player.UserId)
- end)
- if Success and SavedData then
- Rings.Value = SavedData.Rings or 0
- Level.Value = SavedData.Level or 1
- XP.Value = SavedData.XP or 0
- else
- Rings.Value = 0
- Level.Value = 1
- XP.Value = 0
- end
- end
- local function PlayerRemoving(Player: Player)
- local Leaderstats = Player:FindFirstChild("leaderstats")
- if Leaderstats then
- local RingsValue = Leaderstats:FindFirstChild("Rings")
- local LevelValue = Leaderstats:FindFirstChild("Level")
- local XPValue = Player:FindFirstChild("XP")
- if RingsValue and LevelValue and XPValue then
- pcall(function()
- DataStore:SetAsync(Player.UserId, {
- Rings = RingsValue.Value,
- Level = LevelValue.Value,
- XP = XPValue.Value
- })
- end)
- end
- end
- end
- Players.PlayerAdded:Connect(PlayerAdded)
- Players.PlayerRemoving:Connect(PlayerRemoving)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement