How to make Camera to moving Part

Im using this to make the Camera to the Player:

game.ReplicatedStorage:WaitForChild("PassengerRemoteEvent").OnClientEvent:Connect(function()
	
	workspace.CurrentCamera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
	
	workspace.CurrentCamera.CameraType = Enum.CameraType.Custom

end)

And im using this to make the Camera to the Part what inside the Vehicle. The Camera will go to the Driver Cabin Camera but will not move the Camera because its just setting the Position the first Time.

I tried to use CameraSubject but i think i did something wrong how can i set the Camera to the Part and move the Camera with the Part?

game.ReplicatedStorage:WaitForChild("DriverRemoteEvent").OnClientEvent:Connect(function(enableControlsIgnore, player)
	
	--workspace.CurrentCamera.CameraSubject = workspace.Trains:FindFirstChild(player.UserId):WaitForChild("Front"):WaitForChild("Front"):WaitForChild("DriverCabin1Camera1")

	workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable

	workspace.CurrentCamera.CFrame = workspace.Trains:FindFirstChild(player.UserId):WaitForChild("Front"):WaitForChild("Front"):WaitForChild("DriverCabin1Camera1").CFrame
	
end)
1 Like

Instead of using CameraSubject, use the CFrame because when the CameraType becomes Scriptable the Camera no longer uses CameraSubject to determine its position. You want to constantly update the Camera CFrame to the CFrame of the part you want it to be on.

3 Likes

So should i use Runservice Heartbeat and constantly update the CFrame?

1 Like

When i dont have CameraType to scriptable and do CameraSubject to Part would it work?

1 Like

No, use RenderStepped. If you use Heartbeat then the camera movement will be choppy and laggy.

2 Likes

I prefer to use RunService.Stepped. It is even faster then Heartbeat and RenderStepped.

CameraSubject doesnt do anything while the CameraType is Scriptable.

1 Like

It’s unnecessary to use Stepped in camera calculations. The CFrame only needs to be calculated before showing the new frame to the player, so it’s a waste of resources to use Stepped.

1 Like

How to make the camera can be moved in 360° when the left mouse button is pressed.

1 Like