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)
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
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)
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)