Issue with progress bar (math issue)

I’m not the best at math, and I am unable to find a solution that fixes my issue.
The issue is that the bar isn’t calculated correctly.
Here’s my current code:

Bar:TweenSize(UDim2.new(StageValue / MaxStage, 0, Bar.Size.Y.Scale, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Sine, 0.1, true)

Since you only use the scale of x, y you can use UDim2.fromScale instead:

UDim2.fromScale(StageValue/MaxStage, Bar.Size.Y.Scale)

Also your code looks mathematically correct, so the issue may be related to how you anchor the UI(if it’s positioning related) or the values StageValue, MaxStage not being correct(if it’s sizing related). Maybe you update the MaxStage variable manually and you forgot to do so? Or maybe you set StageValue to Stage.Value at the start of your script causing the variable value to remain constant(because that way you save the value not the reference)?

Max stage is 3, my stage is 1, if I do 1 / 3 it overlaps the GUI.

Since this shouldn’t happen, I assume the Bar isn’t a child of the background(the empty bar behind the bar filling), so scaling isn’t related to the background size but another UI size or the window size?

I’m really just guessing here because the issue isn’t related to the line of code you provided since that is correct.

The bar is not a child of the frame. There is no frame.

That’s the issue then, you see when you set the scaling of X to 1 the UI X size is equal to its parent X size. So if your Bar UI isn’t a child of the frame that acts as a background(as in most games) the 1 refers to the total window X size or some bigger general UI on top of the bar, and thus it becomes larger than it should be when you set it to 1/3. This is not a math problem however, it’s a design flaw.

1 Like

Awesome! That was the issue indeed, wasn’t aware of that small error as I rarely touch UI.
Thank you!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.