Help with CFrames | Local positioning

I also had trouble understanding at first, but I think I get it now.

What you want to do it transform the red part’s position to the object space of the blue part - that will allow you to get the X and Y positions, which you presumably want to keep the same. Once you have those, you can teleport the red part to the correct position.

The code for this would look as follows:

--Convert red part's position to blue's object space
local transformedPoint = bluePart.CFrame:pointToObjectSpace(redPart.Position)

--Teleport red part to correct position - maintain X/Y but clear Z
redPart.CFrame = bluePart.CFrame * CFrame.new(transformedPoint.x, transformedPoint.y, 0)

And that should be it!

2 Likes