Tween continues after pausing it

My tween for some reason just continues after pausing it. Here ist he script:

local tween1 = TweenService:Create(camera, TweenInfo.new(160, Enum.EasingStyle.Quad), {CFrame = cameraPart2.CFrame}) 
local tween2 = TweenService:Create(camera, TweenInfo.new(160, Enum.EasingStyle.Quad), {CFrame = cameraPart1.CFrame})
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = cameraPart1.CFrame 

tween1:Play()
tween1.Completed:Connect(function()
	wait(1)
	tween2:Play()
end)

tween2.Completed:Connect(function()
	wait(1)
	tween1:Play()
end)

foundGame.OnClientEvent:Connect(function(color, minutes, chessboard)
	print("Now!")
	tween1:Pause()
	tween2:Pause()
	local cameraShould = chessboard["Camera" .. color]
	print(cameraShould.Name)
	local tweenTo = TweenService:Create(camera, TweenInfo.new(2, Enum.EasingStyle.Quad), {CFrame = cameraShould.CFrame})
	tweenTo:Play()
	tweenTo.Completed:Wait()
	camera.CFrame = cameraShould.CFrame
end)

This is inside of a local script. It does print “Now!” and the rest and it does tween to the target just that after it’s done tweening to the target, tween1/tween2 just continues.

This is not the entire script but I think more isn’t necessary (there are some variables defined on the top like ReplicatedStorage, …).

As you can see, I also tried setting the CFrame of the camera to cameraShould’s CFrame which isn’t working either.

Thanks!

Thanks to someone on discord, I could solve this.
It was because TweenBase.Completed fires on every state change, but it has a playbackState argument, so to fix this, I did

tween1:Play()
tween1.Completed:Connect(function(playbackState)
	if playbackState == Enum.PlaybackState.Completed then
		wait(1)
		tween2:Play()
	end
end)

tween2.Completed:Connect(function(playbackState)
	if playbackState == Enum.PlaybackState.Completed then
		wait(1)
		tween1:Play()
	end
end)
1 Like