After locking to first person, how do I make the camera automatically zoom out back to third person?

I have a script that locks the camera into first person when a part is touched and sets it back to classic (third person) when a different part is touched. However, when it sets to third person, the camera stays in first person so I’m forced to zoom out back to where I was manually. Is there a way to make it so that when switching back to third person, the camera automatically goes back to the zoom it was at before locking to first person?

Here’s the code I have currently:

local plr = game.Players.LocalPlayer
local CameraMode = plr.CameraMode

local FP1 = workspace:WaitForChild("_FirstPersonPart1")
local TP1 = workspace:WaitForChild("_ThirdPersonPart1")

FP1.Touched:Connect(function()
        CameraMode = Enum.CameraMode.LockFirstPerson
end)

TP1.Touched:Connect(function()
        CameraMode = Enum.CameraMode.Classic
end)
5 Likes

Well I think you can work with Player.CameraMaxZoomDistance and Player.CameraMinZoomDistance. Placing both values to the same number will automatically lead the camera where you want it to and then you can set them default again… Maybe that works

2 Likes

How do you set it to where the camera was before locking to first person?

1 Like

Is this something u need?

local player = game.Players.LocalPlayer
local camera = game.Workspace.CurrentCamera
local defaultMaxZoom = player.CameraMaxZoomDistance
local defaultMinZoom = player.CameraMinZoomDistance

local FP1 = workspace:WaitForChild("_FirstPersonPart1")
local TP1 = workspace:WaitForChild("_ThirdPersonPart1")

local function switchToFirstPerson()
	if not player then return end
	player.CameraMaxZoomDistance = 0.1
	player.CameraMinZoomDistance = 0.1 
end

local function switchToThirdPerson()
	if not player then return end
	player.CameraMaxZoomDistance = defaultMaxZoom
	player.CameraMinZoomDistance = defaultMinZoom
end

FP1.Touched:Connect(switchToFirstPerson)
TP1.Touched:Connect(switchToThirdPerson)
1 Like

I wanted it the camera zoom to automatically go back to how it was before locking. This script doesn’t look like it would do exactly that…

I checked online for you but currently there isn’t really a way or a property to detect ur current CameraZoom, so i made a little workaround for you, But sadly you can only input a fixed number

local player = game.Players.LocalPlayer
local defaultMaxZoom = player.CameraMaxZoomDistance
local defaultMinZoom = player.CameraMinZoomDistance

local FP1 = workspace:WaitForChild("_FirstPersonPart1")
local TP1 = workspace:WaitForChild("_ThirdPersonPart1")

local function switchToFirstPerson()
	if not player then return end
	player.CameraMode = Enum.CameraMode.LockFirstPerson
end

local function switchToThirdPerson()
	if not player then return end
	player.CameraMode = Enum.CameraMode.Classic
	player.CameraMaxZoomDistance = defaultMaxZoom
	player.CameraMinZoomDistance = 15
	task.wait()
	player.CameraMinZoomDistance = defaultMinZoom
end
FP1.Touched:Connect(switchToFirstPerson)
TP1.Touched:Connect(switchToThirdPerson)

2 Likes

When using this and testing the game, the screen is completely black

That shouldn’t be happening, atleast it doesn’t in my studio, restart ur studio maybe? Cuz this code wont cause that.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.