Advertisement
bmanbob

BmanBob's saving-script

Oct 21st, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. local datastore = game:GetService("DataStoreService"):GetDataStore("test866818286369716235195685453434369464701")
  2.  
  3. game.Players.PlayerAdded:Connect(function(player)
  4. local lt = Instance.new("Folder")
  5. lt.Name = "leaderstats"
  6. lt.Parent = player
  7.  
  8. local money = Instance.new("IntValue")
  9. money.Name = "Cash"
  10. money.Parent = lt
  11.  
  12. local key = "plr-"..player.userId
  13.  
  14. local getSaved = datastore:GetAsync(key)
  15. if getSaved then
  16. money.Value = getSaved[1]
  17. else
  18. local itemsToSave = {money.Value}
  19. datastore:GetAsync(key, itemsToSave)
  20. end
  21. end)
  22.  
  23. game.Players.PlayerRemoving:Connect(function(player)
  24. datastore:SetAsync("plr-"..player.userId, {player.leaderstats.Cash.Value})
  25. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement