How do I reverse this stamina bar progression?

I currently have a functioning stamina bar, however the way it progresses isn’t exactly what I wanted because the math is off, the stamina bar goes empty when the stamina is full, and the bar goes filled when stamina is empty. I wanted the bar to be full when stamina is full, and empty when stamina is empty.

(Streamable video since I can’t upload video directly in DevForum for some reason, it takes too long to process it.)
https://streamable.com/4x4why

-- Placeholder variables
local PhysicalBar = the surfacegui part
local Energy = 10 -- CURRENT ENERGY, this goes down whenever you press T, and regenerates some time.
local MaxEnergy = 10 -- MAX ENERGY

PhysicalBar.Stamina.SurfaceGui.Main.UIGradient.Offset = Vector2.new(-((Energy / MaxEnergy) * 0.45), 0)

Hmm, not sure why the * .45 is there. But try this:

Vector2.new(1 - (-(Energy / MaxEnergy) * 0.45), 0)

Sorry if this is not what you wanted, can’t really figure out what’s wrong in the video it looks perfectly fine to me :stuck_out_tongue:

1 Like

I multiply it by 0.45 because of the UIGradient offset. If Energy / MaxEnergy is 1, then it will be 0.45, and 0.45 offset will make the blue bar invisible.

The video shows me using up stamina, my stamina decreases from 10 to 9, and so on. When it decreases, the blue bar below my character fills up, and that wasn’t really the way I wanted it to fill up - I wanted the blue, circular bar to be filled when my stamina is full, and decrease when I use stamina.

Oooooh I hadn’t even spotted the blue bar :stuck_out_tongue:

Still, the whole idea of subtracting the value from 1 to “invert” it should still work.

local Energy = 10
local MaxEnergy = 10

print(0.9 - (Energy/MaxEnergy) * 0.45)

Still produces the same result as 0.45 since Energy/MaxEnergy is 1, so if the stamina is max it will still be empty. It also produces weird results when stamina is a lower number (e.g. 0.9 - 5/MaxEnergy * 0.45 = 0.675)

Nevermind. I got it to work, thanks @ThankRoBama for giving the idea, the final formula I used is:

-0.45 - -((Energy / MaxEnergy) * 0.45)
1 Like