Camera setting to the player during transitions

I made a camera tween, and I’m making it so that multiple cameras from different areas have a tween. However, during camera transitions, the camera goes to the player for a split second, how would I avoid this?

Code:

local TweenService = game:GetService("TweenService")
local cams = game.Workspace.Cameras
local done = false

local camera = game.Workspace.Camera

local sceneTime = 20

local tweeninfo = TweenInfo.new(
	sceneTime,
	Enum.EasingStyle.Sine,
	Enum.EasingDirection.Out,
	0,
	false,
	0
)

function tween(camera1, camera2)
	camera.CameraType = Enum.CameraType.Scriptable
	camera.CFrame = camera1.CFrame
	
	local tween = TweenService:Create(camera, tweeninfo, {CFrame = camera2.CFrame})
	tween:Play()
	
	wait(sceneTime)

	camera.CameraType = Enum.CameraType.Custom

end


tween(cams.Camera1, cams.Camera2)
tween(cams.Camera3, cams.Camera4)
tween(cams.Camera5, cams.Camera6)
tween(cams.Camera7, cams.Camera8)
tween(cams.Camera9, cams.Camera10)

The glitch only occurs after the first tween, it doesn’t occur for any of the others, even though they are using the exact same script.

Thanks!

1 Like

This might help:

local TweenService = game:GetService("TweenService")
local cams = game.Workspace.Cameras
local done = false

local camera = game.Workspace.Camera

local sceneTime = 20

local tweeninfo = TweenInfo.new(
	sceneTime,
	Enum.EasingStyle.Sine,
	Enum.EasingDirection.Out,
	0,
	false,
	0
)

function tween(camera1, camera2, ending)
	camera.CameraType = Enum.CameraType.Scriptable
	camera.CFrame = camera1.CFrame
	
	local tween = TweenService:Create(camera, tweeninfo, {CFrame = camera2.CFrame})
	tween:Play()
	
	wait(sceneTime)

	if ending then
		camera.CameraType = Enum.CameraType.Custom
	end

end


tween(cams.Camera1, cams.Camera2, false)
tween(cams.Camera3, cams.Camera4, false)
tween(cams.Camera5, cams.Camera6, false)
tween(cams.Camera7, cams.Camera8, false)
tween(cams.Camera9, cams.Camera10, true)
1 Like

It still flickers slightly to the player, I have no idea why.

1 Like

It also only happens after the first tween, the all the others are fine.

1 Like

Could it have something to do with you setting the camera back to custom after a tween?

1 Like

I tried using @Rald_s 's code, yet it still flickers after the first tween.

1 Like

The issue still occurs after restarting studio, and re-making the camera parts.

1 Like

Why are you making the CameraType Custom?

Isn’t custom the default player camera type?

1 Like

Yes, never mind, I didn’t see the if statement, and thought you were making it custom every time.

1 Like

I am getting this error:
:arrow_forward: ActivateCameraController did not select a module. (x2) - Client - CameraModule:362
But that only happens at the start of the game, and somebody said that it’s a glitch.

If you happen to have a solution that would be great.

1 Like

I assume the reason this happens is because you aren’t waiting for the tween to finish. You’re calling the functions right after each other, without waiting or each of the tweens to complete.

It only happens between tween 1 and 2 though. (the glitch)

1 Like

try putting a wait for the tween time or only calling the function once the previous tween is being completed. Just try, let’s see if anything happens

1 Like

Hmm… after the first tween, it goes straight to the player.
Here’s my code if you need it:

local TweenService = game:GetService("TweenService")
local cams = game.Workspace.Cameras
local done = false

local camera = game.Workspace.Camera

local sceneTime = 20

local tweeninfo = TweenInfo.new(
	sceneTime,
	Enum.EasingStyle.Sine,
	Enum.EasingDirection.Out,
	0,
	false,
	0
)

function tween(camera1, camera2, ending)
	camera.CameraType = Enum.CameraType.Scriptable
	camera.CFrame = camera1.CFrame

	local tween = TweenService:Create(camera, tweeninfo, {CFrame = camera2.CFrame})
	tween:Play()

	wait(sceneTime)

	if ending then
		camera.CameraType = Enum.CameraType.Custom
	end

end


tween(cams.Camera1, cams.Camera2, false)
wait(20)
tween(cams.Camera3, cams.Camera4, false)
wait(20)
tween(cams.Camera5, cams.Camera6, false)
wait(20)
tween(cams.Camera7, cams.Camera8, false)
wait(20)
tween(cams.Camera9, cams.Camera10, true)
1 Like

The only times that I’ve seen a tween glitch out when it comes to camera movements is when another script could be manipulating the camera at the same time. Are there any other scripts that could be setting the camera to the player’s Character during those first few tweens?

1 Like

No, the only script running is a script that tweens UI.

Let me put the scripts into another place, and see how it goes.

1 Like

Is that value in the UI tween set to true? Y’know that value that overrides any other tweens.

It runs the same in another place, and removing all scripts except that one make it still glitch.

1 Like

It worked! Would setting it to true cause any other errors if I don’t have any other camera animations running (except the ones in the script)

1 Like