How do I prevent a player from moving the camera?

I want to prevent the player from moving their camera whilst the camera its CFrame is being set.
However when the player moves the camera, it jitters everywhere.
In the video below I’m trying to move my camera in multiple directions whilst the camera is focusing on a part.
Video:

This is the localscript I use to manipulate the camera. The player activates the tool and the camera will look at a set target.

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

local runService = game:GetService("RunService")

script.Parent.Activated:Connect(function()
	script.Parent.RemoteEvent:FireServer(player, camera)
	runService.RenderStepped:Connect(function()
		camera.CFrame = CFrame.new(camera.CFrame.Position, workspace.Target.Position)
	end)
end)
3 Likes

Change the Camera’s Type to Scriptable. This can be done via:

Camera.CameraType = Enum.CameraType.Scriptable
1 Like

You need to set the Camera.CameraType to Enum.CameraType.Scriptable

This freezes the camera in a stationary position

You can set the cameratype back to custom after

On another note, you should have a connection for when the tool is deactivated. That way you can stop setting the camera cframe and won’t have to deal with memory leaks.

local player = game:GetService("Players").LocalPlayer
local camera = workspace.CurrentCamera

local originalCameraType = camera.CameraType
local cameraConnection

local tool = script.Parent
local remote = tool:WaitForChild("RemoteEvent")

local runService = game:GetService("RunService")

tool.Activated:Connect(function()
	--[[
	remote:FireServer()
	you don't need to pass the player argument because it's already passed to the server.
	Also, camera objects only exist on the client so you can't pass them to the server
	]]--
	if (cameraConnection and cameraConnection.Connected) then return end
	
	originalCameraType = camera.CameraType
	cameraConnection = runService.RenderStepped:Connect(function()
		camera.CFrame = CFrame.new(camera.CFrame.Position, workspace.Target.Position)
	end)
end)

tool.Deactivated:Connect(function()
	if (cameraConnection and cameraConnection.Connected) then
		cameraConnection:Disconnect()
		camera.CameraType = originalCameraType
	end
end)
1 Like

Sorry I didn’t explain too well what I meant.
When you activate the tool, the camera will just freeze and won’t follow the player anymore.

Maybe you can set the camera subject to the part

I want the camera subject to be on the player whilst looking at the part, not the part be the camera subject