Advertisement
PeaPattern

Leaderstats

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