Unable to cancel a UI tween

local function TimerStart(ProgressBar) -- Makes a function, that requires a frame to be defined
	
	local number = (boxNeeded+crateNeeded+barrelNeeded+metalNeeded+woodNeeded) * 20


	local Tween = TweenService:Create(ProgressBar, TweenInfo.new(number/2), {BackgroundColor3 = Color3.new(0.666667, 0, 0)}) 
	ProgressBar:TweenSize(UDim2.new(0, 0, 0.9, 0), nil, nil, number) 
	for i = number, 0, -1 do 
		print(i)
		
		wait(1) 
		done = false
		Tween:Play() 
		wait(2)
		Tween:Cancel()
	end
	progressBar.Size = UDim2.new(1, 0,0.9, 0)
	progressBar.BackgroundColor3 = Color3.new(0, 0.8, 0)

end

it dosn’t cancel after two seconds, how would i make it stop the tween?

1 Like

Try using :Pause(). I think it might help.

No, that won’t help you because you are using a loop, and after it is turned off, it still continues moving to that same point.
You need to either stop the loop or move the menu back to the starting point so it can move again in the same way.
Explain the essence of what you want to do, because it’s not clear at all, since you are changing the frame color in Tween.

i am trying to have it cancel at a event, but i realised tween:cancel wasn’t working, so i deleted that part and did this script, which was to test if tween:cancel is the problem or not, turned out it was, i want to stop the tween and put it back to full

I have a question, does the tween stop for one second at all?
Sure, and if possible, could you provide more details on what needs to be done in general?

local Tween = TweenService:Create(ProgressBar, TweenInfo.new(number/2), {BackgroundColor3 = Color3.new(0.666667, 0, 0)})

ProgressBar:TweenSize(UDim2.new(0, 0, 0.9, 0), nil, nil, number)

You’ve got two tweens. You are only canceling the first one. If you’re trying to cancel the second one, it isn’t going to work.

OH yeah, how could i stop the second one?

You would have to create a Tween with TweenService just like you would with any other tween.

local Tween2 = TweenService:Create(ProgressBar, TweenInfo.new(number), {Size = UDim2.new(0, 0, 0.9, 0)})

-- To stop the tween
Tween2:Cancel()