Make camera switch between top down and 1st person

I am trying to make a camera script that can switch between a top down view and a first person view when X is pressed. However, when I try to press X with the following script in StarterPlayerScripts, it locks the camera in place. I tried other solutions, including one that kind of made a broken version of first person (camera wouldn’t go up or down, was locked to the player’s torso) how do I make it switch between the topdown (which is mode 1 and works perfectly) and first person (mode 2, which I cannot switch to properly)

local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera
local playercam = player.CameraMode
local event = game.Workspace.CamOcclusion
local mode = 1 -- 1 is top down, 2 is first person
local IUS = game:GetService("UserInputService")
print("Camera script started")
player.CharacterAdded:Wait()
player.Character:WaitForChild("HumanoidRootPart")
event:FireServer()
local root = player.Character.HumanoidRootPart
camera.CameraType = Enum.CameraType.Attach
camera.FieldOfView = 90

local RunService = game:GetService("RunService")

local function onUpdate()
	if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
		if mode == 1 then
			camera.CameraType = Enum.CameraType.Attach
			camera.CFrame = CFrame.new(player.Character.HumanoidRootPart.Position) * CFrame.new(0,25,15) * CFrame.Angles(math.rad(-60), 0, 0) --The first two numbers are Height(25) and distance(15). The third is the angle(-60), the lower this variable is the more the camera will face the ground 
			camera.CameraSubject = root
		else
			playercam = Enum.CameraMode.Classic
			camera.CameraSubject = nil
			camera.CameraType = Enum.CameraType.LockFirstPerson

		end
	end
end
 
RunService:BindToRenderStep("Camera", Enum.RenderPriority.Camera.Value, onUpdate)
IUS.InputBegan:Connect(function(input,GPE)
	if input.KeyCode == Enum.KeyCode.X and GPE == false then
                if mode == 1 then
		mode = 2
                else
                mode = 1
                end
	end
end)