Advertisement
Guest User

stat datastores

a guest
Jan 24th, 2020
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. local DataStore = game:GetService("DataStoreService"):GetDataStore("STAT")
  2.  
  3. local function onPlayerAdded(player)
  4. local plr = game.Workspace:WaitForChild(player.Name)
  5. local starterGui = game:GetService('StarterGui')
  6. local stats = Instance.new("Folder", player)
  7. local clife = Instance.new("StringValue", stats)
  8. local cash = Instance.new("IntValue", stats)
  9. local net = Instance.new("IntValue", stats)
  10. local dead = Instance.new("BoolValue", stats)
  11. local data
  12. local data1
  13. local data2
  14. local data3
  15. local data4
  16. pcall(function()
  17. data = DataStore:GetAsync(plr.UserId)
  18. data1 = data[1]
  19. data2 = data[2]
  20. data3 = data[3]
  21. data4 = data[4]
  22. end)
  23. if data4 ~= nil then
  24. if data1 ~= nil then
  25. cash.Value = data1
  26. else
  27. cash.Value = 0
  28. end
  29. if data2 ~= nil then
  30. clife.Value = data2
  31. else
  32. clife.Value = "Life"
  33. end
  34. if data3 ~= nil then
  35. net.Value = data3
  36. else
  37. net.Value = 0
  38. end
  39. if data4 == false then
  40. dead.Value = false
  41. else
  42. dead.Value = true
  43. end
  44. else
  45. dead.Value = false
  46. end
  47. stats.Name = "leaderstats"
  48. clife.Name = "clife"
  49. cash.Name = "cash"
  50. net.Name = "net"
  51. dead.Name = "dead"
  52.  
  53. plr.Torso.Anchored = true
  54. end
  55. local function onPlayerLeave(player)
  56. local plr = game.Workspace:WaitForChild(player.Name)
  57. local starterGui = game:GetService('StarterGui')
  58. local stats = player.leaderstats
  59. local clife = stats.clife
  60. local cash = stats.cash
  61. local net = stats.net
  62. local dead = stats.dead
  63. local data
  64. pcall(function()
  65. data = DataStore:SetAsync(plr.UserId, {
  66. cash.Value,
  67. clife.Value,
  68. net.Value,
  69. dead.Value
  70. })
  71. end)
  72. end
  73.  
  74. game.Players.PlayerAdded:Connect(onPlayerAdded)
  75. game.Players.PlayerRemoving:Connect(onPlayerLeave)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement