Advertisement
HowToRoblox

LevelBarHandler

Sep 11th, 2021
3,834
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.29 KB | None | 0 0
  1. local clipping = script.Parent:WaitForChild("BarClipping")
  2. clipping.ClipsDescendants = true
  3.  
  4. local expTxt = script.Parent:WaitForChild("Experience")
  5. local levelTxt = script.Parent:WaitForChild("Level")
  6.  
  7. local expVal = game.Players.LocalPlayer:WaitForChild("Stats"):WaitForChild("Experience")
  8. local levelVal = game.Players.LocalPlayer.Stats:WaitForChild("Level")
  9.  
  10.  
  11. local previousExp = expVal.Value
  12.  
  13.  
  14. function updateGui()
  15.    
  16.     local neededExp = math.floor(levelVal.Value ^ 1.5 + 0.5) * 500
  17.    
  18.     local previousLevelExp = math.floor((levelVal.Value - 1) ^ 1.5 + 0.5) * 500
  19.    
  20.     local expDiff = neededExp - previousLevelExp
  21.    
  22.     local currentExp = expVal.Value - previousLevelExp
  23.    
  24.  
  25.    
  26.     local x = currentExp / expDiff
  27.    
  28.     clipping.Size = UDim2.new(x, 0, 1, 0)
  29.     clipping.Bar.Size = UDim2.new(1 / x, 0, 1, 0)
  30.            
  31.    
  32.     expTxt.Text = currentExp .. "/" .. expDiff
  33.     levelTxt.Text = "Level " .. levelVal.Value
  34.    
  35.    
  36.     if expVal.Value == neededExp then
  37.        
  38.         local nextExpNeeded = (math.floor((levelVal.Value + 1) ^ 1.5 + 0.5) * 500) - neededExp
  39.        
  40.         expTxt.Text = "0/" .. nextExpNeeded
  41.        
  42.         levelTxt.Text = "Level " .. levelVal.Value + 1
  43.        
  44.         clipping.Size = UDim2.new(0, 0, 1, 0)
  45.     end
  46.    
  47.    
  48.     previousExp = expVal.Value
  49. end
  50.  
  51.  
  52. updateGui()
  53.  
  54. expVal:GetPropertyChangedSignal("Value"):Connect(updateGui)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement