How would I go about making the camera swap between player and back?

I am genuinely confused as to how I can do this, as i’ve been troubleshooting it for quite a bit.

I’ve tried to make it swap from scriptable and custom as to make it go from player to cutscene mode, but still not working, anyways please help me out with this cause it has taken me quite a bit of troubleshooting.

local uis = game:GetService("UserInputService")

local camera = workspace.CurrentCamera

local player = game.Players.LocalPlayer
local character = player.Character
local humanoid = character.Humanoid

local cameraPos = workspace:WaitForChild("CameraPos")

local cutscenePlaying = false

uis.InputBegan:Connect(function(inpObj, gpe)
	if gpe then return end
	print(camera.CameraType)
	if inpObj == Enum.KeyCode.T then
		if cutscenePlaying == false then
			cutscenePlaying = true
		else
			cutscenePlaying = false
		end
	end
end)

game:GetService("RunService").Heartbeat:Connect(function()
	if cutscenePlaying == true then
		camera.CameraType = "Scriptable"
		camera.CFrame = cameraPos
	else
		camera.CameraType = "Custom"
	end
end)

local uis = game:GetService("UserInputService")


local camera = workspace.CurrentCamera
local player = game.Players.LocalPlayer

local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local cameraPos = workspace:WaitForChild("CameraPos")

local cutscenePlaying = false

uis.InputBegan:Connect(function(input, gpe)
	if gpe then return end
	print("CameraType:", camera.CameraType)
	if input.KeyCode == Enum.KeyCode.T then
		cutscenePlaying = not cutscenePlaying
	
	end
end)

game:GetService("RunService").Heartbeat:Connect(function()
	if cutscenePlaying then
		camera.CameraType = Enum.CameraType.Scriptable
		camera.CFrame = cameraPos.CFrame
	else
		camera.CameraType = Enum.CameraType.Custom
	end

end)

You shouldn’t be using run service for this type of camera manipulation since it’s performance heavy. Instead listen for when a flag changes and run the code once. Since you cannot listen for when a Boolean variable changes, create a boolvalue, along with some other fixes

local uis = game:GetService("UserInputService")

local camera = workspace.CurrentCamera

local player = game.Players.LocalPlayer
local character = player.Character
local humanoid = character.Humanoid

local cameraPos = workspace:WaitForChild("CameraPos") — isn’t this a part?

local cutscenePlaying = script.BoolValue

uis.InputBegan:Connect(function(inpObj, gpe)
	if gpe then return end
	print(camera.CameraType)
	if inpObj == Enum.KeyCode.T then
		cutscenePlaying.Value = not cutsenePlaying.Value
	end
end)

cutscenePlaying.Changed:Connect(function()
    if cutscenePlaying.Value == true then
        camera.CameraType = Enum.CameraType.Scriptable
        camera.CFrame = cameraPos.CFrame
    else
        camera.CameraType = Enum.CameraType.Custom
    end
end)