Camera not teleporting script

I am trying to make a script in which when the right mouse button is pressed it teleports the users camera to a part called “cam”.
this is the script:

local player = game.Players.LocalPlayer
local tool = script.Parent
local userInputService = game:GetService("UserInputService")

-- Function to teleport the camera to the Cam part's position
local function teleportCamera()
	local camera = game.Workspace.CurrentCamera
	local camPart = tool:FindFirstChild("cam") -- Move this line inside the function

	if camPart then
		camera.CameraType = Enum.CameraType.Scriptable
		camera.CFrame = CFrame.new(camPart.Position)
	end
end

-- Function to handle mouse button events
local function onInput(input)
	if input.UserInputType == Enum.UserInputType.MouseButton2 then -- Right mouse button
		teleportCamera()
	end
end

-- Connect the function to the mouse button pressed event
userInputService.InputBegan:Connect(onInput)


the script was working before but I touched something and the next day it wouldn’t work

local player = game.Players.LocalPlayer
local tool = script.Parent
local userInputService = game:GetService("UserInputService")

-- Function to teleport the camera to the Cam part's position
local function teleportCamera()
	local camera = game.Workspace.CurrentCamera
	local camPart = tool:FindFirstChild("cam") -- Move this line inside the function

	if camPart then
		camera.CameraType = Enum.CameraType.Scriptable
		camera.CFrame = CFrame.new(camPart.Position)
	end
end


-- Connect the function to the mouse button pressed event
userInputService.InputBegan:Connect(function(Input)
	if input.UserInputType == Enum.UserInputType.MouseButton2 then
teleportCamera()
end
end)

Use workspace.CurrentCamera instead of game.Workspace.CurrentCamera

I have tried that and it doesn’t work with either script, maybe it has something to do with the properties?
it does say this however:
image