HAHOOS

Saving Leaderstats

Sep 17th, 2021
983
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local datastore = game:GetService("DataStoreService")
  2. local cashStorage = datastore:GetDataStore("CashDataStore")
  3.  
  4. game.Players.PlayerAdded:Connect(function(player)
  5.     local leaderstats = Instance.new("Folder")
  6.     leaderstats.Name = "leaderstats"
  7.     leaderstats.Parent = player
  8.     local cash = Instance.new("IntValue")
  9.     cash.Name = "Cash"
  10.     cash.Parent = leaderstats
  11.     cash.Value = cashStorage:GetAsync(player.UserId).Cash
  12. end)
  13.  
  14. game.Players.PlayerRemoving:Connect(function(player)
  15.     local data = {
  16.         Cash = player:FindFirstChild("leaderstats").Cash.Value
  17.     }
  18.     cashStorage:SetAsync(player.UserId, data)
  19. end)
RAW Paste Data