Advertisement
PeaPattern

Leaderstats

Apr 17th, 2024
541
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.37 KB | None | 0 0
  1. local DSService = game:GetService("DataStoreService")
  2. local Players = game:GetService("Players")
  3. local RStorage = game:GetService("ReplicatedStorage")
  4.  
  5. local Codes = DSService:GetDataStore("CodesPlrs")
  6. local DS_Clicks = DSService:GetOrderedDataStore("Clicks")
  7. local DS_Rebirths = DSService:GetOrderedDataStore("Rebirths")
  8.  
  9. local CodeList = require(RStorage.Modules.Codes)
  10.  
  11. Players.PlayerAdded:Connect(function(Player)
  12.     local Leaderstats = Instance.new("Folder")
  13.     Leaderstats.Parent = Player
  14.     Leaderstats.Name = "leaderstats"
  15.    
  16.     local Clicks = Instance.new("IntValue")
  17.     Clicks.Parent = Leaderstats
  18.     Clicks.Name = "Clicks"
  19.    
  20.     local Rebirths = Instance.new("IntValue")
  21.     Rebirths.Parent = Leaderstats
  22.     Rebirths.Name = "Rebirths"
  23.    
  24.     pcall(function()
  25.         if not Codes:GetAsync(Player.UserId) then
  26.             local Compiled = {}
  27.             for code, callback in CodeList do
  28.                 Compiled[code] = true
  29.             end
  30.             Codes:SetAsync(Player.UserId, Compiled)
  31.         end
  32.     end)
  33.    
  34.     pcall(function()
  35.         Clicks.Value = DS_Clicks:GetAsync(Player.UserId) or 0
  36.     end)
  37.    
  38.     pcall(function()
  39.         Rebirths.Value = DS_Rebirths:GetAsync(Player.UserId) or 0
  40.     end)
  41. end)
  42.  
  43. Players.PlayerRemoving:Connect(function(Player)
  44.     pcall(function()
  45.         DS_Clicks:SetAsync(Player.UserId, Player.leaderstats.Clicks.Value)
  46.     end)
  47.    
  48.     pcall(function()
  49.         DS_Rebirths:SetAsync(Player.UserId, Player.leaderstats.Rebirths.Value)
  50.     end)
  51. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement