my code:
local Player = game.Players.LocalPlayer
local Character = Player.Character
local MainFrame = script.Parent
local Camera = workspace.CurrentCamera
local Humanoid = Character.Humanoid

local Exceptions = {
	FP = function()
	end,
	ExcludedFrame2 = function()
	end,
	-- if the player presses a button that is not supposed to have a frame,
	-- the code in here will run.
}

local function onButtonClick(button)
	if Exceptions[button.Name] then
		Exceptions[button.Name]()
	else
		local targetFrame = MainFrame.Parent:FindFirstChild(button.Name)
		if targetFrame and targetFrame:IsA("Frame") then
			targetFrame.Visible = true
			print("Frame named '" .. targetFrame.Name .. "' is now visible.")
		else
			warn("Frame named '" .. targetFrame.Name .. "' not found.")
		end
	end
end

for _, child in MainFrame:GetChildren() do
	if child:IsA("TextButton") then
		child.MouseButton1Click:Connect(function()
			onButtonClick(child)
		end)
	end
end


other code:

wait(1);
cam = workspace.CurrentCamera;
pal = game.Players.LocalPlayer.Character;
local Player = game.Players.LocalPlayer
local mouse = Player:GetMouse()
local run = game:GetService("RunService")
local maxDegree = math.rad(80)

deb = "TPS";

function updatetransparency(targ,bool)
	for i,v in pairs(targ:GetChildren()) do
		if v:IsA("Accessory") then
			updatetransparency(v,bool)
		elseif v:IsA("BasePart") then
			--HatAttachment FaceCenterAttachment HairAttachment NeckAttachment
			if v:FindFirstChild("HatAttachment") or v:FindFirstChild("FaceCenterAttachment")
				or v:FindFirstChild("FaceFrontAttachment")
				or v:FindFirstChild("FaceRearAttachment")
				or v:FindFirstChild("HairAttachment") or v:FindFirstChild("NeckAttachment") then
				if bool then
					v.LocalTransparencyModifier = 1					
				else
					v.LocalTransparencyModifier = v.Transparency
				end
			end
		end
	end
end

function updatechartransparency(targ,bool)
	for i,v in pairs(targ:GetChildren()) do
		if v:IsA("BasePart") then
			if bool or v.Name == "Head" then
				v.LocalTransparencyModifier = 1					
			else
				v.LocalTransparencyModifier = v.Transparency
			end
			updatetransparency(v,bool)
		elseif v:IsA("Folder") or v:IsA("Model") then
			updatetransparency(v,bool)
		end
	end
end

local renderrrrrr = game:GetService("RunService").RenderStepped;
script.Parent.MouseButton1Click:connect(function()
	if deb == "FPS" then
		if Player.Character then
			cam.CameraType = "Custom";
			deb = "TPS"
			local char = Player.Character
			if char:FindFirstChild("Humanoid") then
				cam.CameraSubject = char.Humanoid
				script.Parent.Parent.PreviewFP.Text = "IN THIRD PERSON VIEW"
				cam.FieldOfView = 70
			end
			updatetransparency(Player.Character)
		end
	elseif deb == "TPS" then
		if Player.Character then
			cam.CameraType = "Custom";
			deb = "TPSHead"
			local char = Player.Character
			if char:FindFirstChild("Head") then
				cam.CameraSubject = char.Head
				script.Parent.Parent.PreviewFP.Text = "IN THIRD PERSON VIEW (HEAD FOCUS)"
				cam.FieldOfView = 70
			end
			updatetransparency(Player.Character)
		end
	elseif deb == "TPSHead" then
		cam.CameraType = "Scriptable";
		deb = "FPS"
		script.Parent.Parent.PreviewFP.Text = "IN FIRST PERSON VIEW"
		
		if Player.Character then
			updatetransparency(Player.Character,true)
			updatechartransparency(Player.Character)
			cam.FieldOfView = 90
		end
		while true do
			if Player.Character then
				local char = Player.Character

				if char:FindFirstChild("Head") then
					local np = Vector2.new(mouse.X, mouse.Y)
					local centre = Vector2.new(cam.ViewportSize.X/2, cam.ViewportSize.Y/2)
					local difference = np - centre

					local outcome = Vector2.new((difference.Y/centre.Y)*maxDegree, (difference.X/centre.X)*maxDegree)

					cam.CFrame = char.Head.CFrame
						* CFrame.new(0,0,(-char.Head.Size.Z/2)*1.25)
						* CFrame.Angles(-outcome.X, -outcome.Y,0)
				end
			end
			renderrrrrr:wait();
			if deb ~= "FPS" or not Player.Character then
				break;
			end;		
		end;
	end
	
	--[[
	local np = Vector2.new(mouse.X, mouse.Y)
	local centre = Vector2.new(cam.ViewportSize.X/2, cam.ViewportSize.Y/2)
	local difference = np - centre

	local outcome = Vector2.new((difference.Y/centre.Y)*maxDegree, (difference.X/centre.X)*maxDegree)

	cam.CFrame = campartttt.CFrame * CFrame.Angles(-outcome.X, -outcome.Y,0)
	]]
end);

add the CameraSubject switch from the other code to my code; it should be inside the FP function.