Math.Clamp (Exp Bar goes outside the window)

Hey, I have been coding a level system for some reason I can’t fix that the exp bar goes outside the window I have tried using math.clamp but I have no idea how it works I have also tried using this forum post but I just can’t get it to work this is my code


(screenshot course formatting did not work)
I’m sure I’m missing something obvious but does anybody know the reason?

this is how it looks rn

1 Like

here is an explication of math.clamp.
which means you’re not using it correctly.

It’s not necessary to clamp the value between 0,1 since you’re already dividing it’s value by the max xp amount. Instead clamp it between 0 and expmax, that should fix it.

1 Like

You aren’t using the variable storing the result of math.clamp at all. Instead you should replace (Exp.Value/expmax.Value) with the clamped result:

local exp = math.clamp(Exp.Value/expmax.Value, 0, 1)
script.Parent.UpperBar.Size = UDim2.fromScale(exp, 1) --where 1 is the height
2 Likes