I’m working on a foot placement script, but I can’t figure how to set the position of the legs, and they look really weird

Script;

```
local function ResolverIK(OrigenCF, Meta, L1, L2)
local Localizado = OrigenCF:PointToObjectSpace(Meta);
local UnidadLocalizada = Localizado.Unit;
local L3 = Localizado.Magnitude;
local Axis = Vector3.new(0, 0, -1):Cross(UnidadLocalizada);
local Angulo = math.acos(-UnidadLocalizada.Z);
local Angulo2 = math.acos(-UnidadLocalizada.Y);
local PlanoCF = OrigenCF*CFrame.fromAxisAngle(Axis, Angulo);
if L3 < math.max(L2, L1)-math.min(L2, L1) then
return PlanoCF*CFrame.new(0, 0, math.max(L2, L1)-math.min(L2, L1)), -math.pi/2, math.pi;
elseif L3 > L1+L2 then
return PlanoCF, math.pi/2, 0;
else
local A1 = -math.acos((-(L2*L2)+(L1*L1)+(L3*L3))/(2*L1*L3));
local A2 = math.acos(((L2*L2)-(L1*L1)+(L3*L3))/(2*L2*L3));
return PlanoCF, A1+math.pi/2, A2+A1;
end
end
local function R15IK(Shoulder, Elbow, Meta, Valor_C0, C0)
local UpperArm = Elbow.Part0;
local LowerArm = Elbow.Part1;
local UpperTorsoCF = Shoulder.Part0.CFrame;
local R0, R1 = UpperArm.Size.Y-.25, LowerArm.Size.Y-.25;
local Plano, ShoulderAngulo, ElbowAngulo = ResolverIK(UpperTorsoCF*Valor_C0, Meta, R0, R1);
Shoulder.C0 = UpperTorsoCF:ToObjectSpace(Plano)*CFrame.Angles(ShoulderAngulo, 0, 0);
Elbow.C0 = C0*CFrame.Angles(ElbowAngulo, 0, 0);
end
local Psj = script.Parent;
local Hip = Psj:WaitForChild("RightUpperLeg").RightHip;
local Elbow = Psj:WaitForChild("RightLowerLeg").RightKnee;
local Hip2 = Psj:WaitForChild("LeftUpperLeg").LeftHip;
local Knee = Psj:WaitForChild("LeftLowerLeg").LeftKnee;
local C0 = Elbow.C0;
local C02 = Knee.C0;
local Valor_C0 = CFrame.new(Hip.C0.p);
local Valor_C02 = CFrame.new(Hip2.C0.p);
local HRP = Psj.PrimaryPart;
while wait() do
if math.abs(HRP.Velocity.X) > 0 then
local Rayo = Ray.new(Vector3.new(HRP.Position.X, HRP.Position.Y, HRP.Position.Z)+Hip.C0.p+Psj.Humanoid.MoveDirection, Vector3.new(0, -9999, 0));
local _, Posicion = workspace:FindPartOnRayWithIgnoreList(Rayo, {Psj});
local Rayo2 = Ray.new(Vector3.new(HRP.Position.X, HRP.Position.Y, HRP.Position.Z)+Hip2.C0.p+Psj.Humanoid.MoveDirection, Vector3.new(0, -9999, 0));
local _, Posicion2 = workspace:FindPartOnRayWithIgnoreList(Rayo2, {Psj});
R15IK(Hip, Elbow, Posicion, Valor_C0, C0);
R15IK(Hip2, Knee, Posicion2, Valor_C02, C02);
end
end
```

Video;