Need help with pausing tweens

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    In my game I have a while loop that makes the current camera pan from side to side.
  2. What is the issue? Include screenshots / videos if possible!
    But when the player switches to a different cam, the tween will start freaking out and taking the player back to the other camera, sometimes not even switching cameras
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I attempted to look for solutions but I don’t think anyone has something similar to this.
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
    Here’s the code:
game.Workspace.Office.PlayerActions:WaitForChild("Camera").Changed:Connect(function()
	local cam2 = game.Workspace.Office.PlayerActions.Camera
	task.wait(1)
	local cam3 =  game.Workspace.Office.PlayerActions.Camera.Value
	local move1 = tweenservice:Create(cam, tweeninfo4, {CFrame = game.Workspace.Cameras:FindFirstChild(cam2.Value).CamPart1.CFrame})
	local move2 = tweenservice:Create(cam, tweeninfo4, {CFrame = game.Workspace.Cameras:FindFirstChild(cam2.Value).CamPart2.CFrame})
	while true  do
		move1:Play()
		task.wait(6)
		
		move2:Play()
		task.wait(6)
	end
end)

If you guys could tell me how to stop this from happening that would be great.

Why don’t you just pause the tween like so:

animation:Pause()
-- After whatever and you want it to resume where it left off:
animation:Play()

im just using this as a response to the topic’s title

Sorry, I should’ve explained what I meant better. I know how to pause tweens, I’m just not really sure when or how I should do it when the player will be constantly changing cameras.

You could check if any other tween is playing (when attempting to start a new transformation / tween). Then, if there is another one playing; you could just pause it or smthn like that.

That’s the problem. The code I wrote immediately makes new tweens with new parts each time you change cameras. I don’t know if I can save a tween and then use that save in a new changed function.

You could probably use _G (THIS IS DEPRECATED PROBABLY SHOULDNT USE THIS) or you could use getfenv and setfenv.