[SOLVED] Problems with Legs pointing toward the location

I am making a Foot Planting systems, and I’ve already finished the scripts that bend legs.
And I’m making the part which legs point toward the location.
I’ve already visited 2 Joint 2 Limbs Inverse Kinematics, and I’ve used one script from there. But moves weirdly.

Video about the leg movement:

Script:

while wait(0.1) do
	local RightHipCFrame = LowerTorso.Parent.UpperTorso.CFrame * SavedLocationOfRightHipC0
	local basePlane = CFrame.new(RightHipCFrame.Position, game.Workspace.Ankle.Position)
	
	RightHip.C0 = LowerTorso.Parent.UpperTorso.CFrame:ToObjectSpace(basePlane)
end

What should I change or fix?

You are forgetting about the second line.

local shoulderAngle = CFrame.Angles(A + math.pi/2, 0, 0)

A is the angle to be solved, for now leave it as 0.

while wait(0.1) do
	local RightHipCFrame = LowerTorso.Parent.UpperTorso.CFrame * SavedLocationOfRightHipC0
	local basePlane = CFrame.new(RightHipCFrame.Position, game.Workspace.Ankle.Position)
	local shoulderAngle = CFrame.Angles(math.pi/2, 0, 0)

	RightHip.C0 = LowerTorso.Parent.UpperTorso.CFrame:ToObjectSpace(basePlane)*shoulderAngle 
end

The reason is due to how CFrame.new(pos1, pos2) works which aligns only the LookVector towards the target object. To amend this we rotate 90 degrees along the legs local X axis after the transformation.