Making a joint face a position?

I’m trying to make my character’s right leg face a set position, but I’m not exactly the best with CFrames. I experimented for an hour or two and got something. This code is just a placeholder for experimenting, just FYI.

local rightHip = workspace.Agent.Torso["Right Hip"]; 

local rLegC0 =, -1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1);
local rLegC1 =, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1);

function getRotation(position)
	position = position or workspace.PosPart.Position;

	local targetCF = * rLegC0).Position, position);
	local x, y, z = targetCF:ToEulerAnglesYXZ();

	return CFrame.Angles(x, y, z)

rightHip.C1 = rLegC1;
rightHip.C1 *= getRotation();

I used a part to test out how my code runs, and it faces in the general direction of the test part, but ultimately doesn’t work that well. When too far back or too far in front of the dummy, it starts to face the opposite way.
It doesn’t even work diagonally.

When positioned behind the dummy:


When directly under:


When positioned diagonally:

All help is appreciated!