Make camera1 go back to camera2 smoothly

I am trying to make it go to camera1 → camera2 → camera1 → camera2 in a loop…

But the problem is that it goes like this camera1 → camera2 → camera1 → camera2 but it goes to camera 1 instantly when it reaches camera2, heres the script and a diagram of what I want.

local tweenService = game:GetService("TweenService")

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local camera = workspace.CurrentCamera

local camera1 = workspace:WaitForChild("Camera1")
local camera2 = workspace:WaitForChild("Camera2")

local cutsceneTime = 10
	
local tweenInfo = TweenInfo.new(cutsceneTime, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, -1, false, 1)

local function tween1(camera1, camera2)
	camera.CameraType = Enum.CameraType.Scriptable
	
	camera.CameraSubject = camera1
	camera.CFrame = camera1.CFrame

	local tween1 = tweenService:Create(camera, tweenInfo, {CFrame = camera2.CFrame})

	tween1:Play()
	tween1.Completed:Wait()
	
	camera.CameraSubject = camera2
	camera.CFrame = camera2.CFrame

	local tween2 = tweenService:Create(camera, tweenInfo, {CFrame = camera1.CFrame})

	tween2:Play()
	tween2.Completed:Wait()
end

tween1(camera1, camera2)

image

Why did you delete it???

You already set the camera type.

Oh ok, do you have a solution though?

It snaps back because the first tween is always repeating

Do you know how to prevent this???

You might need to make another TweenInfo variable with Reversing = true

I changed the repeat to 0 and just put the tween in a while wait() do loop and it seems to work.

You don’t need a wait() in the loop because the loop already yields while waiting for the tweens to complete so you can just do

while true do
    tween1(camera1, camera2)
end

before you start the tween, do:
workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable

OP already has that in their code inside the tween1 function

local tweenService = game:GetService("TweenService")
local cutsceneTime = 10
local tweenInfo = TweenInfo.new(cutsceneTime, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, 0, false, 1)

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local camera = workspace.CurrentCamera

local camera1 = workspace:WaitForChild("Camera1")
local camera2 = workspace:WaitForChild("Camera2")


local function tween1(camera1, camera2)
	camera.CameraType = Enum.CameraType.Scriptable
	camera.CameraSubject = camera1
	camera.CFrame = camera1.CFrame

	local tween1 = tweenService:Create(camera, tweenInfo, {CFrame = camera2.CFrame})
	tween1:Play()
	tween1.Completed:Wait()
	
	camera.CameraSubject = camera2
	camera.CFrame = camera2.CFrame

	local tween2 = tweenService:Create(camera, tweenInfo, {CFrame = camera1.CFrame})
	tween2:Play()
	tween2.Completed:Wait()
end

while true do
	if script.Parent.Playing.Value == true then
		camera.CameraSubject = humanoid
		camera.CameraType = Enum.CameraType.Custom
		break
	else
		tween1(camera1, camera2)
	end
end

Right now when they click play and the values changes it doesn’t stop the loop.

local tweenService = game:GetService("TweenService")
local cutsceneTime = 10
local tweenInfo = TweenInfo.new(cutsceneTime, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, 0, false, 1)

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local camera = workspace.CurrentCamera

local camera1 = workspace:WaitForChild("Camera1")
local camera2 = workspace:WaitForChild("Camera2")

local playing = script.Parent:WaitForChild("Playing")

local currentTween
local function tween(cameraStart, cameraEnd)
	-- if player is already playing, then don't start a new camera tween
	if playing.Value == true then
		return
	end
	camera.CameraType = Enum.CameraType.Scriptable
	camera.CameraSubject = cameraStart
	camera.CFrame = cameraStart.CFrame

	currentTween = tweenService:Create(camera, tweenInfo, {CFrame = cameraEnd.CFrame})
	currentTween:Play()
	currentTween.Completed:Wait()
end

-- when playing is changed to true, change the camera back to the player and clean up the tween and connection
local connection
connection = playing:GetPropertyChangedSignal("Value"):Connect(function()
	if playing.Value == true then
		camera.CameraSubject = humanoid
		camera.CameraType = Enum.CameraType.Custom
		connection:Disconnect()
		currentTween:Cancel()
	end
end)

-- while not playing, tween camera from camera1 to camera2 and back
while not playing.Value do
	tween(camera1, camera2)
	tween(camera2, camera1)
end