Trying to update a tween without removing it's easing progress

Right now, I am working on a custom tween function which will slow down, speed up or completely stop when a number is changed.

Here is the current code:

function module:Tween(obj,tim,info,prop,ts)
	local start=tick()
	local ti=tim
	
	local tween=game:GetService("TweenService"):Create(obj,TweenInfo.new(ti,info[1],info[2]),prop)
	local prev=ts:GetAttribute("TimeScale")
	tween:Play()
	
	while obj and obj.Parent and task.wait() do
		if prev~=ts:GetAttribute("TimeScale") then
			if ts:GetAttribute("TimeScale")<=0 then
				tween:Pause()
			else
				tween=game:GetService("TweenService"):Create(obj,TweenInfo.new((ti-(tick()-start))/ts:GetAttribute("TimeScale"),info[1],info[2]),prop)
				tween:Play()
			end
		end
		
		prev=ts:GetAttribute("TimeScale")
		if prev>0 and ((ti-(tick()-start))*ts:GetAttribute("TimeScale"))<=0 then break end
	end
end

When the TimeScale value is changed, it will make another tween that keeps going but is changed in a way where it can proceed either faster or slower (or it will pause if the TimeScale is 0 but that’s not important right now).

(obj is the tweened object, tim is the duration, info are the easingstyle & easingdirection’s, prop are properties & ts is the object containing the TimeScale value that controls this tween)

Only issue is, if a certain EasingStyle is used (for example, Sine), it will reset the progress on the ease which gives off the wrong effect I’m going for here.

If you do understand and have a solution, please assist me in fixing this.
Thank you.

1 Like

Problem still present. Bumping.

1 Like