Help making my turret follow the camera lookvector

Hey guys I need help to find an offset to rotate the gun turret to the Camera CFrame. how can I do this?
So it only rotates to the direction camera is facing?

Player.CameraMode = Enum.CameraMode.LockFirstPerson;

game:GetService("RunService").Heartbeat:Connect(function()

	Gun.Support.Rotate.C0 = Offset * CFrame.Angles() -- rotation!!

	if (Camera.CameraSubject ~= Gun.Gun.Aimpart) then
		Camera.CameraSubject = Gun.Gun.Aimpart;
	end;
	
end)
``
1 Like

I tried this solution but this happens;

game:GetService("RunService").Heartbeat:Connect(function()

	local X,Y,Z = Camera.CFrame:ToOrientation()
	
	local hit = Mouse.Hit;

	local direction = Camera.CFrame.Position + Camera.CFrame.LookVector.Unit * 5000

	local rootCFrame = Gun.Support.CFrame;
	local rotationOffset = (rootCFrame - rootCFrame.p):inverse();

	Gun.Support.Rotate.Transform = rotationOffset * CFrame.new(Vector3.new(0, 0, 0), Vector3.new(direction.X,direction.Y,direction.Z))
	
	
	if (Camera.CameraSubject ~= Gun.Gun.Aimpart) then
		Camera.CameraSubject = Gun.Gun.Aimpart;
	end;
	
end)