Camera Tool Alternative

Now that I found a solution for clicking a button to activate a cutscene, I’m currently working on adding a camera system to my game. The system works by using a tool with a LocalScript inside; the tool is located in the StarterPack. The script is posted below, for reference. It’s connected to a part in Workspace named “Cam(#)”. However, for some unknown reason, the game isn’t compatible with this. If anyone has any solutions, I’d be happy to try them out.

Thank you.

--On the camera part, the stud is the front surface (where the Camera will face), and the inlet is the top surface.
local cameraPart = workspace.Cam1 --Replace with path of camera brick. Make camera brick invisible.
script.Parent.Equipped:Connect(function()
	workspace.CurrentCamera.CameraSubject = cameraPart
	workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
	workspace.CurrentCamera.CFrame = cameraPart.CFrame
	workspace.CurrentCamera.FieldOfView = "25"
end)

script.Parent.Unequipped:Connect(function()
	workspace.CurrentCamera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
	workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
	workspace.CurrentCamera.FieldOfView = "70"
end)

What do you mean by it isn’t compatible?

I’ve added the part and Tool in the game multiple times, and it does not work. However, it works in my other games.

Is the part unanchored for whatever reason?

It’ll get destroyed if it falls through the map.

It’s anchored, it’s just the when I select the tool to activate the camera, it does not show up or anything.

So when the tool is equipped it does nothing?

You are correct. This does not happen in any other game, just the one I’m working on right now.

You might have code that’s messing with the camera somewhere else. You can try this code and see if this fixes the problem:

local cameraPart = workspace.Cam1 --Replace with path of camera brick. Make camera brick invisible.
local connection
script.Parent.Equipped:Connect(function()
	workspace.CurrentCamera.CameraSubject = cameraPart
	workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
	if connection.Connected then connection:Disconnect() end
	connection = workspace.CurrentCamera:GetPropertyChangedSignal("CameraType"):Connect(function()
		workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
		workspace.CurrentCamera.CameraSubject = cameraPart
	end)
	workspace.CurrentCamera.CFrame = cameraPart.CFrame
	workspace.CurrentCamera.FieldOfView = 25
end)

script.Parent.Unequipped:Connect(function()
	workspace.CurrentCamera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
	if connection.Connected then connection:Disconnect() end
	workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
	workspace.CurrentCamera.FieldOfView = 70
end)

This code isn’t super great practice, though if this works and the other code doesn’t it means another script is messing with the camera.

It is still not working. This message does keep popping up in the Output tab, however.

Cam1 is not a valid member of Workspace "Workspace"

That means that Cam1 isn’t in workspace. That’s your problem.

That’s the thing. It is in the Workspace. It’s the same name for the part and the same name in the LocalScript.

You might need to wait for the Cam1 to be added:

local cameraPart = workspace:WaitForChild("Cam1") --Replace with path of camera brick. Make camera brick invisible.
script.Parent.Equipped:Connect(function()
	workspace.CurrentCamera.CameraSubject = cameraPart
	workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
	workspace.CurrentCamera.CFrame = cameraPart.CFrame
	workspace.CurrentCamera.FieldOfView = "25"
end)

script.Parent.Unequipped:Connect(function()
	workspace.CurrentCamera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
	workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
	workspace.CurrentCamera.FieldOfView = "70"
end)