Advertisement
Guest User

yans script

a guest
Jan 23rd, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1.  
  2. local DataStoreService = game:GetService("DataStoreService")
  3.  
  4. local myDataStore = DataStoreService:GetDataStore("myDataStore")
  5.  
  6. game.Players.PlayerAdded:Connect(function(player)
  7. local leaderstats = Instance.new("Folder")
  8. leaderstats.Name = "leaderstats"
  9. leaderstats.Parent = player
  10.  
  11. local cash = Instance.new("IntValue")
  12. cash.Name = "Fame"
  13. cash.Parent = leaderstats
  14.  
  15. local data
  16. local success, errormessage = pcall(function()
  17. data = myDataStore:GetAsync(player.UserId.."-cash")
  18. end)
  19.  
  20. if success then
  21. cash.Value = data
  22. else
  23. print("There was an error while getting your data")
  24. warn("errormessage")
  25. end
  26. end)
  27.  
  28. game.Players.PlayerRemoving:Connect(function(player)
  29.  
  30. local success, errormessage = pcall(function()
  31. myDataStore:SetAsync(player.userId.."-cash",player.leaderstats.Fame.Value)
  32. end)
  33.  
  34. if success then
  35. print("Player Data successfully saved!")
  36. else
  37. print("There was error when saving data")
  38. warn(errormessage)
  39. end
  40.  
  41. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement