Advertisement
guy56890

Roblox Data store script

Oct 11th, 2019
8,363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. Roblox Datastore script:
  2.  
  3. local DSService = game:GetService("DataStoreService")
  4. local DS = DSService:GetDataStore("DataStore1")
  5.  
  6. game.Players:PlayerAdded:Connect(function(player)
  7.  
  8. local leaderstats = Instance.new("Folder", player)
  9. leaderstats.Name = "leaderstats"
  10.  
  11. local cash = Instance.new("IntValue", leaderstats)
  12. cash.Name = "Cash"
  13. cash.Value = 0
  14.  
  15.  
  16.  
  17. local success, error = pcall(function()
  18. player:GetAsync(game.Players.LocalPlayer.leaderstats.Cash)
  19. end)
  20.  
  21. if success then
  22. print("Successfully achieved".. player.Name.."'s data!")
  23. end
  24.  
  25. if error then
  26. warn("An error occured while loading data. Error:".. error ..". Player name:".. player.Name)
  27. end
  28.  
  29. end)
  30.  
  31. game.Players.PlayerRemoving:Connect(function(player)
  32. local success, error = pcall(function()
  33. DS:SetAsync(game.Players.LocalPlayer.leaderstats.Cash, player.UserId)
  34. end)
  35.  
  36. if success then
  37. print("Successfully saved data to".. player.Name)
  38. end
  39.  
  40. if error then
  41. warn("An error occured while the player was leaving. Error:".. error ..". Player name:".. player.Name)
  42. end
  43.  
  44. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement