Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. local DataStoreService = game:GetService("DataStoreService")
  2. DataStore=game:GetService("DataStoreService"):GetGlobalDataStore()
  3. local Players = game:GetService("Players")
  4.  
  5. PlayerStats = game.Lighting.PlayerStats
  6. local Stats = PlayerStats:clone()
  7.  
  8.  
  9. Class = "Warrior"
  10. Gold = 0
  11. Health = 100
  12. XP = 0
  13. PVP = false
  14. Level = 1
  15. Magic = 0
  16.  
  17.  
  18. function onPlayerAdded(player)
  19. local Players = game:GetService("Players")
  20. if player:FindFirstChild("PlayerStats")==nil then
  21. Stats.Parent = player
  22. end
  23. playersave1 = DataStoreService:GetDataStore(player.UserId, Gold)
  24. --playersave2 = DataStoreService:GetDataStore(player.UserId, "Class")
  25. playersave3 = DataStoreService:GetDataStore(player.UserId, Health)
  26. playersave4 = DataStoreService:GetDataStore(player.UserId, XP)
  27. playersave5 = DataStoreService:GetDataStore(player.UserId, Level)
  28. playersave6 = DataStoreService:GetDataStore(player.UserId, Magic)
  29.  
  30.  
  31.  
  32.  
  33. player:WaitForChild("PlayerStats")
  34. local playerstatus = player:FindFirstChild("PlayerStats")
  35. --playerstatus.Class.Value = playersave2
  36. playerstatus.Class.Value = DataStore:GetAsync(player.UserId, Class)
  37. playerstatus.Health.Value = DataStore:GetAsync(player.UserId, Health)
  38. playerstatus.XP.Value = DataStore:GetAsync(player.UserId, XP)
  39. playerstatus.Level.Value = DataStore:GetAsync(player.UserId, Level)
  40. playerstatus.Magic.Value = DataStore:GetAsync(player.UserId, Magic)
  41. playerstatus.Gold.Value = DataStore:GetAsync(player.UserId, Gold)
  42. --[[
  43. playerstatus.Gold.Value = playersave1
  44. playerstatus.Health.Value = playersave3 --or 100
  45. playerstatus.XP.Value = playersave4 --or 0
  46. playerstatus.Level.Value = playersave5-- or 1
  47. playerstatus.Magic.Value = playersave6 --or 0
  48. ]]
  49. print("UpdatedStats")
  50. print("Loading: "..player.Name.."Data")
  51. end
  52. --else
  53.  
  54. function onPlayerRemoved(player)
  55. pcall(function()
  56. playersave1 = player.PlayerStats.Gold.Value
  57. playersave2 = player.PlayerStats.Class.Value
  58. playersave3 = player.PlayerStats.Health.Value
  59. playersave4 = player.PlayerStats.XP.Value
  60. playersave5 = player.PlayerStats.Level.Value
  61. playersave6 = player.PlayerStats.Magic.Value
  62. playersave1:SetAsync(player.UserId, Gold)
  63. playersave2:SetAsync(player.UserId, Class)
  64. playersave3:SetAsync(player.UserId, Health)
  65. playersave4:SetAsync(player.UserId, XP)
  66. playersave5:SetAsync(player.UserId, Level)
  67. playersave6:SetAsync(player.UserId, Magic)
  68.  
  69. end)
  70. print("Saving: "..player.Name.." Data")
  71. end
  72.  
  73.  
  74.  
  75. Players.PlayerAdded:Connect(onPlayerAdded)
  76. Players.PlayerRemoving:Connect(onPlayerRemoved)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement