Advertisement
Jemstone135

LeaderstatsDataSave Script

Oct 16th, 2020
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. -- This is a script we use to make a game called "The Prison: Behind Bars".
  2. -- This is a Leaderstats Data Save script
  3.  
  4. local dss = game:GetService("DataStoreService")
  5.  
  6. local DataStoreToKeep = dss:GetDataStore("TypeWhatYouWantHere")
  7.  
  8. game.Players.PlayerAdded:Connect(function(player)
  9. local ls = Instance.new("Folder",player)
  10. ls.Name = "leaderstats"
  11.  
  12. local money = Instance.new("IntValue",ls)
  13. money.Name = "Money"
  14. money.Value = 0
  15.  
  16. local data
  17. local success, errormessage = pcall(function()
  18. data = DataStoreToKeep:GetAsync(player.UserId.."-money")
  19. end)
  20. if success then
  21. money.Value = data
  22. else
  23. warn(errormessage)
  24. end
  25. end)
  26.  
  27. game.Players.PlayerRemoving:Connect(function(player)
  28.  
  29. local success, errormessage = pcall(function()
  30. DataStoreToKeep:SetAsync(player.UserId.."-money",player.leaderstats.Money.Value)
  31. end)
  32. if success then
  33. else
  34. warn(errormessage)
  35. end
  36. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement