GUI Percentage Bar Tweening Problem

First, here’s the GUI bar that I’m trying to resize.
SaturationBarGUI
That white bar you see above, is a bar I’m trying to resize based on a number between -1, and 1 that comes from ColorCorrection’s Saturation value.

game.Lighting.ColorCorrection.Saturation

If ColorCorrection’s current Saturation Value is 0, the bar should be halfway filled.
If ColorCorrection’s current Saturation Value is -1, the bar should be empty.
If ColorCorrection’s current Saturation Value is 1, the bar should be completely full.

Under normal circumstances, something like this would work
Bar.Size = UDim2.new(x/max_x,0,1,0)

That would typically return a value between 0 - 1 that could be inputted into UDim2’s X.Scale value.

However, since I’m dealing with a number that can become -1, this does not work the same since a UDim2’s X.Scale value can not be negative in this situation.

Math is not my strongest, I’m sure by using math.abs() this can be solved. I just haven’t quite found the solution yet.

Sorry if this post isn’t the most well written or concise. Any help is appreciated.

local function GetInterpolant(n: number, min: number, max: number): number
	local absmin = math.abs(min)
	n += absmin
	min += absmin
	max += absmin
	
	return math.clamp(n / max, 0, 1)
end

in your case:
n would be the slider value set by the player within range [min, max]
min and max would be whatever the min/max values are

set the X component of your UDim2 value to the return value of the function

1 Like

Dope, this is better than adding 0.05 / -0.05 to the X.Scale value.
Thank you much.

1 Like

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