Positioning two parts relative to attachments

Hey everyone!

I wanted two make a script that, given two parts (let’s call them partA and partB) with an attachment inside, would position the parts such that the CFrames of the two attachment coincide. Something like this:

I have made this script, which works but only for parts with the same orientation…

local partA = workspace.PartA
local partB = workspace.PartB

partB.CFrame *= partA.Attachment.WorldCFrame:ToObjectSpace(partB.Attachment.WorldCFrame):Inverse()

Any ideas on how to make this work? I’ve searched in the DevForum and the documentation for anything, but to no avail…
Any help is appreciated!!

EDIT: I want to specify that the script should consider the orientation offset of the attachment (ex. if partA’s attachment is tilted 60 degrees, then partB’s should follow that orientation)

1 Like

Something like this should work:

partB.CFrame = partA.CFrame * partA.Attachment.CFrame * partB.Attachment.CFrame:Inverse()
3 Likes

Thanks so much man, it works splendidly!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.