Need help with slider math

Hello!

I have this slider which works fairly well but I am a little bit stuck on how I would handle the value which would be the progress of the slider.

This first part controls the position of the slider:

currentConnections[#currentConnections + 1] = mouse.Move:Connect(function()
	local y = mouse.Y
	local topBoundary = 0
	local bottomBoundary = sliderBounds.AbsoluteSize.Y
	local mousePos = y - sliderBounds.AbsolutePosition.Y
	local scaledPosition = math.clamp(mousePos, topBoundary, bottomBoundary) / bottomBoundary
	notch.Position = UDim2.new(
		notch.Position.X.Scale,
		notch.Position.Y.Scale,
	    scaledPosition,
		0
	)
end)

Now, the problem I am facing is that I don’t know how I would scale the position up relatively to the lower and upper bounds of the value.

If the minimum value is -10 and the maximum value is 10, how would I go about scaling it up proportionately to this value?

If the notch’s Y position is 1/3 of the whole slider, what formula could I use so the returned value is 1/3 of the position between -10 and 10 if that makes sense?

Represent the slider position by a number in the range [0, 1] and calculate the value by doing something like:

local Value = MinValue + (MaxValue - MinValue) * SliderValue

This is an example of lerping (linear interpolation) - equation start + (goal - start) * alpha.

You might’ve heard of lerping in the context when you e.g. lerp two CFrames.

1 Like