So everytime i level up the gui gets all bigg and im not sure how to fix it
local player = game.Players.LocalPlayer
local CurrentExp = player:WaitForChild("leaderstats").Exp
local MaxExp = player:WaitForChild("leaderstats").ExpToLevel
local Gui = script.Parent
local Exterior = Gui:WaitForChild("BackFrame")
local label = Gui:WaitForChild("TextLabel")
local Bar = Gui:WaitForChild("Expbar")
script.Parent.TextLabel.Text = CurrentExp.Value.."/"..MaxExp.Value
CurrentExp.Changed:Connect(function()
script.Parent.TextLabel.Text = CurrentExp.Value.."/"..MaxExp.Value
if CurrentExp.Value >= MaxExp.Value then
Bar.Size = UDim2.new(CurrentExp.Value/MaxExp.Value,0,1,0)
wait(0.5)
CurrentExp.Value = 0
Bar.Size = UDim2.new(CurrentExp.Value/MaxExp.Value,0,1,0)
else
Bar.Size = UDim2.new(CurrentExp.Value/MaxExp.Value,0,1,0)
end
end)
Hello, the progress bar becomes big because your currentExp is a thousand times larger than the MaxExp. If you want to fix this, just avoid making the currentExp value a lot bigger than the MaxExp value.
Or to highlight an answer from one of my threads, you can just use math.clamp() on the bar.
Instead of adding .Changed just add while loop.
If that doesn’t work then pls show me the gui object in your explorer.
script.Parent.TextLabel.Text = CurrentExp.Value.."/"..MaxExp.Value
while wait() do
script.Parent.TextLabel.Text = CurrentExp.Value.."/"..MaxExp.Value
if CurrentExp.Value >= MaxExp.Value then
CurrentExp.Value = 0
Bar.Size = UDim2.new(CurrentExp.Value/MaxExp.Value,0,1,0)
else
Bar.Size = UDim2.new(CurrentExp.Value/MaxExp.Value,0,1,0)
end
end
Did you replace every UDim2? In my experience, it should work because math.clamp accepts three values; (num, min, and max) and if the num exceeds the max, it will always return max. Other than that I don’t know the problem.
Hello, I don’t think using while wait() do makes a difference from .Changed, while wait() do just causes the script to run every 0.03 seconds even when it is not needed and when the user experience remains stationary. However, using .Changed will only change the bar when the user experience updates.