Advertisement
GaryScripts

Roblox Leaderstats Script (UPDATED!)

Dec 2nd, 2019
13,997
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.67 KB | None | 0 0
  1. -- make sure to have a script inside of ServerScriptService.
  2.  
  3. local DataStore = game:GetService("DataStoreService"):GetDataStore("ValueSave")
  4.  
  5. game.Players.PlayerAdded:Connect(function(plr)
  6.     local leaderstats = Instance.new("Folder", plr)
  7.     leaderstats.Name = "leaderstats"
  8.  
  9.     local Points = Instance.new("IntValue", leaderstats)
  10.     Points.Name = "Points"
  11.     Points.Value = DataStore:GetAsync(plr.userId) or 0
  12.  
  13.     Points.Changed:Connect(function()
  14.         DataStore:SetAsync(plr.userId, Points.Value)
  15.     end)
  16. end)
  17.  
  18. game.Players.PlayerRemoving:Connect(function(plr)
  19.     DataStore:SetAsync(plr.userId, plr.leaderstats.Points.Value)
  20. end)
  21.  
  22. -- Credits to GaryScripts for scripting the code.
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement