How can I figure out the math for this smooth transition?

I am wondering how I can figure out a math equation to create a smooth transition with any number I choose for the max_Sprint. The issue is that the tweenService plays my tween too quickly before the Current_Sprint can count down. Therefore, it does not create a non-stop smooth movement from side to side. It moves, then stops, and then moves again.

local Max_Sprint = 10
local current_Sprint = Max_Sprint --(HERE)
local Bar = script.Parent

local goal = {} --Used for tween service.
local tweenInfo;
local tween;

while true do
   wait()
    if current_Sprint >= 0 then
		wait(0.1) --(HERE)
			
		current_Sprint = current_Sprint - 1 --(HERE)

        goal = {} --Used for tween service.
	    goal.Size = UDim2.new((current_Sprint/Max_Sprint), 0, Bar.Size.Y.Scale, 0)
	    tweenInfo = TweenInfo.new(0.1) --(HERE)
	    tween = tweenService:Create(Bar, tweenInfo, goal) --Create a smooth transition.
	    tween:Play()
	else
		break;
     end
end

Is there some kind of math equation I can use to make it so the bar will smoothly and steadily go from side to side with any max number I choose? I placed comments that say “HERE” for where I think the issue persists. The timing of all of it is wrong and must correspond to each other thus why I am wondering if there is some equation I can use to automatically set that stuff based on the max number that I chose for max sprint.

Try using lerp. It prob is a gud choice.

Can I possibly get some examples?

W8 i meant sumthin else. Try using:

ReplaceWithYourGuiFrame:TweenSize(UDim2.fromScale(currentSprint / maxSprint, YourGuiFramesnormalYscale))

Iam assuming your using a horizontal health bar as this scriptcworks on tht.

I’m assuming this is for a sprint bar which reduces I size when the player sprints. Why don’t you just tween the size of the bar and pause it when they stop sprinting? This would definitely be more efficient, rather than continuously recreating a tween. If you had a background frame which exactly matched the size of the original sprinting frame you could then tween it back to the original size using the size of this frame as a reference.

You could use a PID for a kinda cool springy effect, or you could just move it towards the point using lerping like suggested

For example:

local alpha = 0.5

while true do
    --other random stuff related to your code
    local x_size = (current_size +current_sprint/max_sprint)*alpha
    --set size
end

Alpha is a value between 0 and 1
1 results in instant movement, 0 results in no movement and it will never reach the goal, and anything in between
Smaller is slower, bigger is faster