Advertisement
xmaanzach

leaderstats [XP BAR]

Jul 29th, 2019
768
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. -- Script by xmaanzach
  2.  
  3. local DataStore = game:GetService("DataStoreService")
  4.  
  5. local Nivel = 1
  6. local Experiencia = 0
  7. local XP_Necesaria = 20
  8.  
  9. Nivel = DataStore:GetDataStore("Niveles")
  10. Experiencia = DataStore:GetDataStore("Experiencia")
  11. XP_Necesaria = DataStore:GetDataStore("XPN")
  12.  
  13. --// Creando el leaderstats //--
  14.  
  15. game.Players.PlayerAdded:Connect(function(Player)
  16.  
  17. local PlayerId = tostring(Player.UserId)
  18. local leaderstats = Player:FindFirstChild("leaderstats")
  19.  
  20. if leaderstats == nil then
  21. leaderstats = Instance.new("Folder")
  22. leaderstats.Name = "leaderstats"
  23. leaderstats.Parent = Player
  24. end
  25.  
  26. local Level = leaderstats:FindFirstChild("Nivel")
  27.  
  28. if Level == nil then
  29. Level = Instance.new("IntValue")
  30. Level.Name = "Nivel"
  31. end
  32.  
  33. local Exp = leaderstats:FindFirstChild("Experiencia")
  34.  
  35. if Exp == nil then
  36. Exp = Instance.new("IntValue")
  37. Exp.Name = "Experiencia"
  38. end
  39.  
  40. local Xpn = leaderstats:FindFirstChild("ExpNeeded")
  41.  
  42. if Xpn == nil then
  43. Xpn = Instance.new("IntValue")
  44. Xpn.Name = "ExpNeeded"
  45. end
  46.  
  47. Level.Value = Nivel:GetAsync(PlayerId) or 1
  48. Exp.Value = Experiencia:GetAsync(PlayerId) or 0
  49. Xpn.Value = XP_Necesaria:GetAsync(PlayerId) or 20
  50.  
  51. Level.Parent = leaderstats
  52. Exp.Parent = leaderstats
  53. Xpn.Parent = leaderstats
  54.  
  55. Exp.Changed:Connect(function()
  56. if Player.leaderstats.Experiencia.Value >= Player.leaderstats.ExpNeeded.Value then
  57. Level.Value = Level.Value + 1
  58.  
  59. Xpn.Value = math.floor(Xpn.Value * 2)
  60. Exp.Value = 0
  61.  
  62. Nivel:SetAsync(PlayerId, Level.Value)
  63. Experiencia:SetAsync(PlayerId, Exp.Value)
  64. XP_Necesaria:SetAsync(PlayerId, Xpn.Value)
  65. end
  66. end)
  67. end)
  68.  
  69. --// Guardando los Datos cuando el jugador abandona el juego //--
  70.  
  71. game.Players.PlayerRemoving:Connect(function(Player)
  72. local PlayerId = tostring(Player.UserId)
  73.  
  74. Nivel:SetAsync(PlayerId, Player.leaderstats.Nivel.Value)
  75. Experiencia:SetAsync(PlayerId, Player.leaderstats.Experiencia.Value)
  76. XP_Necesaria:SetAsync(PlayerId, Player.leaderstats.ExpNeeded.Value)
  77. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement