Point Of view Script

I have made this Point of view Script but it is when you Press V it goes to first person or third.
Cant seem to get it to work maybe its where I have it or something in the code. If anyone can help me much will be appreciated.

Local player = game.Players.LocalPlayer
local camera = game.Workspace.CurrentCamera
local humanoid = player.Character:WaitForChild(“Humanoid”)
local currentCameraType = Enum.CameraType.Custom

– Set up the camera to be in third person mode initially
camera.CameraType = Enum.CameraType.Custom
camera.CFrame = humanoid.RootPart.CFrame + Vector3.new(0, 3, -8)
camera.CameraSubject = humanoid

– Switches the camera view between first person and third person modes
local function switchCameraView()
if currentCameraType == Enum.CameraType.Custom then
currentCameraType = Enum.CameraType.Scriptable
camera.CameraType = currentCameraType
humanoid.CameraOffset = Vector3.new(0, 0, 0)
else
currentCameraType = Enum.CameraType.Custom
camera.CameraType = currentCameraType
camera.CameraSubject = humanoid
camera.CFrame = humanoid.RootPart.CFrame + Vector3.new(0, 3, -8)
end
end

– Listens for the V key to be pressed
game:GetService(“UserInputService”).InputBegan:Connect(function(input, gameProcessed)
if not gameProcessed and input.KeyCode == Enum.KeyCode.V then
switchCameraView()
end
end)

Looks like you’re missing the line to set the camera’s CFrame to the RootPart CFrame in your function when you want them in first person. When you set it back to third person you have this line

camera.CFrame = humanoid.RootPart.CFrame + Vector3.new(0, 3, -8)

But you’re missing this line when you want it to be first person

camera.CFrame = humanoid.RootPart.CFrame

Adding that made it work for me.