How to rotate one part relative to another?

  1. What do you want to achieve?

I want to rotate the part on the another part axis

  1. What is the issue?


    Im rotating leg depending on the normal vector of the surface(baseplate), but i want to keep leg rotated 0 degrees on the HumanoidRootPart’s Yaxis, so it should look like that:

    As you can see, leg now rotated almost at 0 degrees on HumanoidRootBody’s Yaxis

  2. What solutions have you tried so far?
    Didn’t find any solution on forum, i tried to read CFrame docs, but did’t find anything helpful(maybe i missed something, so maybe CFrame really can help)

local RRayRes = workspace:Raycast(RP.Position, (RP.CFrame.LookVector/10 - RP.CFrame.UpVector + RP.CFrame.RightVector/4) * 5, RAYPARAMS)
if RRayRes then
	RFootDest.WorldCFrame = CFrame.new(RRayRes.Position + Vector3.new(0, 0.05, 0), RRayRes.Normal)
	RFootIKControl.Enabled = true
end