To use AlignPosition, you need a center part that has the AlignPosition inside of it. From the looks of your code, it would be the “MainPart” object.
To get this to work, you will need to put an attachment and an AlignPosition inside of the MainPart object. Set the “mode” property of the AlignPosition to “OneAttachment”, and set the attachment property of the AlignPosition to the attachment you added to the MainPart earlier. Set the “MaxForce” property of the AlignPosition to a really giant number, and keep adding zeros to that number until Roblox Studio displays the number as “inf”.
Inside your code, replace the line where it says “previewobject:SetPrimaryPartCFrame” with alignPosition.Position = objectcframe.Position, where the alignPosition variable is the AlignPosition of the MainPart.
Also, while I was testing this method, I noticed that since the AlignPosition is very responsive, the part might get very violently moved to the destination. My solution to this is to use an AlignOrientation to correct the orientation and to set the rotation of the part. To get an AlignOrientation to work, it’s mostly the same steps as the AlignPosition.
With an AlignOrientation, which I will refer to as “AO” for brevity, you will need to add an AO and an attachment into the MainPart, set the AO’s mode to OneAttachment, and set the attachment to the attachment you added to the MainPart. Set the AO’s MaxTorque to a really big number that Studio displays as infinite, and then set the responsiveness property to 200.
As for your code, you will need to add a new line below the one setting the AlignPosition’s position. In that new line, you should write
previewobject.MainPart.AlignOrientation.CFrame = CFrame.new(0,0,0) * objectangles
ALSO, a few KEY THINGS TO NOTE:
- The MainPart needs to be unanchored.
- If the model has other parts, the other parts need to be welded to the MainPart
If I’m correct, this should be essentially the same as setting the PrimaryPart’s CFrame, except instead of setting an anchored part’s CFrame, you’re instead using the Roblox physics engine.