Help with FNAF game office camera

Im trying to make a Five Nights At Freddys game and I’m making the custom camera script, but its not facing the correct direction. Why is this happening?

RunService.RenderStepped:Connect(function()
	if PlayerCharacter:WaitForChild("Player"):WaitForChild("isNightGuard").Value and not game.ReplicatedStorage:FindFirstChild("GameData"):FindFirstChild("inCams").Value then
		CurrentCamera.CFrame = CFrame.new(game.Workspace.NightguardPosition.CFrame.Position, Mouse.UnitRay.Direction * 10)
	end
end)

The NightguardPosition part is in the correct position and orientation.
I’ve tried many variations of the camera script but they all have the same result, please help?

Be sure to make sure that the part’s front face is facing the correct way. You can view the part’s front face by adding a hinge by using the Building Tools plugin.

This is likely why. You are setting the CFrame based on the part’s position AND the mouse’s position at the same time. You’ll need to remove the mouse part and set the camera’s CFrame based on the part’s CFrame.

Im trying to set the camera to change direction based on the mouse’s position

Yes, You can do that in another function, but for the initial setup you don’t need it.

1 Like

Its facing the right direction now but it doesn’t face correctly towards the mouse

RunService.RenderStepped:Connect(function()
	if PlayerCharacter:WaitForChild("Player"):WaitForChild("isNightGuard").Value and not game.ReplicatedStorage:FindFirstChild("GameData"):FindFirstChild("inCams").Value then
		CurrentCamera.CFrame = CFrame.new(game.Workspace.NightguardPosition.CFrame.Position)
		CurrentCamera.CFrame = CFrame.new(CurrentCamera.CFrame.Position, Mouse.UnitRay.Direction * 10)
	end
end)

Fixed it by using the script from @Crictoli

1 Like