Advertisement
lucky4291

Advanced Exp System

Aug 19th, 2018
13,912
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.94 KB | None | 0 0
  1. --Script made by lucky4291. Tutorial found here:
  2. --https://www.youtube.com/watch?v=fwbW__5mS5c&feature=youtu.be
  3.  
  4. --Leaderstats Script (Server Script)
  5. local level = 1
  6. local exp = 0
  7. local axp = 20
  8.  
  9. local InStudio = game:GetService("RunService"):IsStudio()
  10.  
  11. if not InStudio then
  12. level = game:GetService("DataStoreService"):GetDataStore("Levels")
  13. exp = game:GetService("DataStoreService"):GetDataStore("EXP")
  14. axp = game:GetService("DataStoreService"):GetDataStore("AXP") -- Amount of exp needed to level up.
  15. end
  16.  
  17. function savedata(dataname, playerid, value)
  18. if InStudio then return end
  19. dataname:SetAsync(playerid, value)
  20. end
  21.  
  22. game.Players.PlayerAdded:connect(function(player)
  23. local leader = Instance.new("Folder")
  24. leader.Name = "leaderstats"
  25. leader.Parent = player
  26. local levelz = Instance.new("IntValue")
  27. levelz.Name = "Level"
  28. local xpz = Instance.new("NumberValue")
  29. xpz.Name = "Exp"
  30. local xpn = Instance.new("IntValue")
  31. xpn.Name = "ExpNeeded"
  32.  
  33. if not InStudio then
  34. xpn.Value = axp:GetAsync(tostring(player.userId)) or 20
  35. xpz.Value = exp:GetAsync(tostring(player.userId)) or 0
  36. levelz.Value = level:GetAsync(tostring(player.userId)) or 1
  37. else
  38. xpn.Value = axp
  39. xpz.Value = exp
  40. levelz.Value = level
  41. end
  42.  
  43. levelz.Parent = leader
  44. xpz.Parent = leader
  45. xpn.Parent = leader
  46.  
  47. xpz.Changed:connect(function()
  48. if player.leaderstats:WaitForChild("Exp").Value >= player.leaderstats:WaitForChild("ExpNeeded").Value then
  49. levelz.Value = levelz.Value + 1
  50.  
  51. --[[Here's a cool formula you can try out for higher exp
  52. n = level
  53. a = exp required to level up
  54.  
  55. a = ((n(n+1)/2)*100
  56. ]]
  57.  
  58. xpn.Value = math.floor(xpn.Value * 2) --You can change this if you want.
  59. xpz.Value = 0
  60.  
  61. savedata(level, player.userId, levelz.Value)
  62. savedata(exp, player.userId, xpz.Value)
  63. savedata(axp, player.userId, xpn.Value)
  64. else
  65. savedata(level, player.userId, levelz.Value)
  66. savedata(exp, player.userId, xpz.Value)
  67. savedata(axp, player.userId, xpn.Value)
  68. end
  69. savedata(level, player.userId, levelz.Value)
  70. savedata(exp, player.userId, xpz.Value)
  71. savedata(axp, player.userId, xpn.Value)
  72. end)
  73. end)
  74.  
  75. game.Players.PlayerRemoving:connect(function(player)
  76. savedata(level, player.userId, player.leaderstats.Level.Value)
  77. savedata(exp, player.userId, player.leaderstats.Exp.Value)
  78. savedata(axp, player.userId, player.leaderstats.ExpNeeded.Value)
  79. end)
  80.  
  81. --Animation Script (Local Script)
  82. local player = game.Players.LocalPlayer
  83. local exp = player:WaitForChild("leaderstats"):WaitForChild("Exp")
  84. local axp = player:WaitForChild("leaderstats"):WaitForChild("ExpNeeded")
  85.  
  86. while true do
  87. wait()
  88. local expBarSize = (exp.Value/axp.Value) - 0.02
  89. if exp.Value == 0 then
  90. expBarSize = 0
  91. script.Parent:TweenSize(UDim2.new(expBarSize, 0, 0, 20), "Out", "Quad", 0.25)
  92. else
  93. script.Parent:TweenSize(UDim2.new(expBarSize, 0, 0, 20), "Out", "Quad", 0.25)
  94. end
  95. end
  96.  
  97. --ExpText Script (Local Script)
  98. local player = game.Players.LocalPlayer
  99. local exp = player:WaitForChild("leaderstats"):WaitForChild("Exp")
  100. local axp = player:WaitForChild("leaderstats"):WaitForChild("ExpNeeded")
  101.  
  102. while true do
  103. wait()
  104. script.Parent.Text = "EXP: " .. exp.Value .. "/" .. axp.Value
  105. end
  106.  
  107. --GetLevel Script (Local Script)
  108. local player = game.Players.LocalPlayer
  109. local level = player:WaitForChild("leaderstats"):WaitForChild("Level")
  110.  
  111. script.Parent.Text = "Current Level: " .. level.Value
  112.  
  113. level.Changed:Connect(function(value)
  114. script.Parent.Text = "Current Level: " .. value
  115. end)
  116.  
  117. --GiveExp Script (Server Script)
  118. local PlayersService = game:GetService("Players")
  119.  
  120. local function onTouch(hit)
  121. local player = PlayersService:GetPlayerFromCharacter(hit.Parent)
  122. local expPoints = player:findFirstChild("leaderstats")
  123. if expPoints ~= nil then
  124. local points = expPoints:findFirstChild("Exp")
  125. if points ~= nil then
  126. points.Value = points.Value + 5
  127. end
  128. end
  129. end
  130.  
  131. script.Parent.Touched:connect(onTouch)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement