How to make Motor6D rotate towards part on one axis through DesiredAngle property

I tried multiple variations of this

while true do
	local dist = (hingePart.Position - obj.Position)
	local angle = math.atan2(-dist.Z,dist.X) 
	
	Motor6D.DesiredAngle = angle
	--Motor6D.Transform = CFrame.Angles(0,0,angle)
	wait(0.5)
end

I tried changing values around, adding 90 degrees, but to no avail, it seems to be off from the target by a varying amount depending on it’s position.

The red part should be pointing at the gray part on the floor.