Locking Camera To a Part

  1. What do you want to achieve?

I would like to create a system to lock every player’s camera to their own camera part. Similar systems across multiple games include:

Age of Empires,
Frostpunk

  1. What is the issue?

A. The camera is not even set when the game begins
B. From there, how do I “weld” the player’s camera to the part so that when it moves so does the camera

  1. What solutions have you tried so far?

None, since it should be working according to the multiple resources I have looked at.

This is the code I have written so far, to no effect:

local Parts = {
	AxisPart = Instance.new("Part", workspace),
	TiltPart = Instance.new("Part", workspace)
}

for i, v in pairs(Parts) do
	
	v.Anchored = true
	v.Massless = true
	v.CanCollide = false
	v.CFrame = v.CFrame * CFrame.new(0,10,0)
	v.Size = Vector3.new(3,3,3)
	v.Material = Enum.Material.SmoothPlastic
	v.Transparency = 1
	
	if v == Parts.TiltPart then
		v.Rotation = Vector3.new(0, 0, 45)
		v.Transparency = 0
	end
end

task.wait(0.01)

local CurrentCamera = workspace.CurrentCamera
CurrentCamera.CameraType = Enum.CameraType.Scriptable
CurrentCamera.CFrame = Parts.TiltPart.CFrame

Thank you.

Place CurrentCamera.CFrame = Parts.TiltPart.CFrame in a .Heartbeat function mayhaps?

Put Camera.CFrame = cameraPart.CFrame in a RenderStepped loop

game:GetService("RunService").RenderStepped:Connect(function(dt)
      camera.CFrame = cameraPart.CFrame

end)