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:
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)?
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.
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.