Trouble with Camera Manipulation

So I’m trying to make a script that makes your camera be on a part (if that makes sense). The script doesn’t work though, and there are no errors on the output. Basically it does change your camera type to fixed, but the camera doesn’t move to the “CameraPart”

local rs = game:GetService("ReplicatedStorage")
local event = rs:WaitForChild("ChangeCamera")

event.OnClientEvent:Connect(function(player, which)
	local camera = game.Workspace.CurrentCamera
	camera.CameraType = Enum.CameraType.Custom
	

	if which == 1 then
		camera.CFrame = game.Workspace.CameraPart1.CFrame
		camera.CameraSubject = game.Workspace.CameraPart1.CFrame
	elseif which == 2 then
		camera.CameraSubject = game.Workspace.CameraPart2.CFrame
		camera.CFrame = game.Workspace.CameraPart.CFrame
		
	end
	
	task.wait()
	camera.CameraType = Enum.CameraType.Fixed
end)

“player” isn’t passed through client event resulting in “which” to be nil and your if statement only picks up values 1 and 2. Also keep the CameraType as custom or it will revert it’s changes.

event.OnClientEvent:Connect(function(which)

Sorry, but can you tell me how to fix it(just the part where “player” isn’t passed through)? I understand how the remote event works to some extent but I’m not too sure on how I can fix it.

Try this:

local rs = game:GetService("ReplicatedStorage")
local event = rs:WaitForChild("ChangeCamera")

event.OnClientEvent:Connect(function(which)
	local camera = game.Workspace.CurrentCamera
	camera.CameraType = Enum.CameraType.Custom
	
	if which == 1 then
		camera.CFrame = game.Workspace.CameraPart1.CFrame
		camera.CameraSubject = game.Workspace.CameraPart1
	elseif which == 2 then
        camera.CFrame = game.Workspace.CameraPart.CFrame
		camera.CameraSubject = game.Workspace.CameraPart2
	end
end)
1 Like

Oh, thanks for the help, I really appreciate it.