Annoying camera manipulation delay

I made code for a shop that would manipulate the camera, and when going from the shop back to the normal camera, it is always extremely delayed, even after I increase how long the loading screen time is. It’s also inconsistent, where sometimes it takes longer than other times.

Here is the code for the shop camera

function shopCamToggle()
	if shopCamEnabled == false then
		shopCamEnabled = true
		changeCam = false
		
		Camera.CameraType = "Scriptable"

		Camera.Changed:Connect(function()
			if Camera.CameraType ~= "Scriptable" and changeCam == false then
				Camera.CameraType = "Scriptable"
			end
		end)

		Camera.CFrame = shopCam.CFrame
		Camera.FieldOfView = 80
		
		camTiltRight = TweenService:Create(Camera, titleInfo, {CFrame = Camera.CFrame * CFrame.Angles(0,0,math.rad(1))})
		camTiltLeft = TweenService:Create(Camera, titleInfo, {CFrame = Camera.CFrame * CFrame.Angles(0,0,math.rad(-1))})
		
		camCoroutine = coroutine.create(function()
			while true do
				camTiltRight:Play()
				camTiltRight.Completed:Wait()
				camTiltLeft:Play()
				camTiltLeft.Completed:Wait()
			end
		end)
		
		coroutine.resume(camCoroutine)
		
	else
		changeCam = true
		Camera.CameraType = "Custom"
		Camera.FieldOfView = 100

		shopCamEnabled = false
		coroutine.close(camCoroutine)
	end
end

Anything helps, thanks!

1 Like

Try this, it might work:

function shopCamToggle()
	if shopCamEnabled == false then
		shopCamEnabled = true
		changeCam = false
		
		Camera.CameraType = "Scriptable"

		Camera.Changed:Connect(function()
			if Camera.CameraType ~= "Scriptable" and changeCam == false then
				Camera.CameraType = "Scriptable"
			end
		end)

		Camera.CFrame = shopCam.CFrame
		Camera.FieldOfView = 80
		
		camTiltRight = TweenService:Create(Camera, titleInfo, {CFrame = Camera.CFrame * CFrame.Angles(0,0,math.rad(1))})
		camTiltLeft = TweenService:Create(Camera, titleInfo, {CFrame = Camera.CFrame * CFrame.Angles(0,0,math.rad(-1))})
		
		camCoroutine = coroutine.create(function()
			while true do
				camTiltRight.Completed:Connect(function()
					camTiltRight:Play()
				end)
				camTiltRight:Play()
				camTiltRight.Completed:Wait()

				camTiltLeft.Completed:Connect(function()
					camTiltLeft:Play()
				end)
				camTiltLeft:Play()
				camTiltLeft.Completed:Wait()
			end
		end)
		
		coroutine.resume(camCoroutine)
		
	else
		changeCam = true
		Camera.CameraType = "Custom"
		Camera.FieldOfView = 100

		shopCamEnabled = false
		coroutine.close(camCoroutine)
	end
end

1 Like
function shopCamToggle()
	if shopCamEnabled == false then
		shopCamEnabled = true
		changeCam = false
			Camera.CameraType = "Scriptable"

		Camera.Changed:Connect(function()
			if Camera.CameraType ~= "Scriptable" and changeCam == false then
				Camera.CameraType = "Scriptable"
			end
		end)

		-- Use a Tween to smoothly transition the camera
		local tweenInfo = TweenInfo.new(1) -- Adjust the duration as needed
		local tween = TweenService:Create(Camera, tweenInfo, {CFrame = shopCam.CFrame, FieldOfView = 80})
		tween:Play()

		camTiltRight = TweenService:Create(Camera, titleInfo, {CFrame = Camera.CFrame * CFrame.Angles(0,0,math.rad(1))})
		camTiltLeft = TweenService:Create(Camera, titleInfo, {CFrame = Camera.CFrame * CFrame.Angles(0,0,math.rad(-1))})
		
		camCoroutine = coroutine.create(function()
			while true do
				camTiltRight:Play()
				camTiltRight.Completed:Wait()
				camTiltLeft:Play()
				camTiltLeft.Completed:Wait()
			end
		end)
		
		coroutine.resume(camCoroutine)
		
	else
		changeCam = true
		Camera.CameraType = "Custom"
		Camera.FieldOfView = 100

		shopCamEnabled = false
		coroutine.close(camCoroutine)
	end
end

I’m stupid, hopefully this works.

It didn’t even go to the shop camera :skull:
Based on your code, it should have worked

1 Like

The problem i’m having is when exiting the shop, and the camera remains in the shop for a split second

Turns out, when setting the camera mode back to Custom, there is a physical delay and I’m not sure why.