Position a Part Relative to Another

Position a Part Relative to Another

Mar 30 2021, 5:21 AM PST


You want to position a part relative to another part.


Use the CFrame:toWorldSpace method.

local part = Instance.new('Part')
part.Parent = Workspace
part.Anchored = true
part.CFrame = CFrame.new(0, 5, 0):toWorldSpace(Workspace.Part)


In this code we set a newly created part’s Articles/Understanding CFrame|CFrame to be 5 studs higher than then CFrame of Workspace.Part. Say that Workspace.Part is in the center of the map. We have another position that’s (0, 5, 0). It will be located five studs above Workspace.Part. However Workspace.Part is not in the center, it’s somewhere else. When we call CFrame:toWorldSpace we use what Workspace.Part, but create a new CFrame that keeps the relativity of CFrame.new(0, 5, 0) to Workspace.Part. Resulting in a new CFrame which is five studs higher than Workspace.Part.

  • positioning
  • part
  • coding
  • script