model:Clone() only moves parts, children models stay in place

Issue: When cloning a model, the parts and welded parts in the object clone to the set position. However, remaining models (and parts in folders) that are connected via attachments are not moved, instead staying in the place they had been while in ServerStorage.

Request: Suggestions or help on how to set the position of a model relative to a second model, and how to clone a model in its entirety rather than just the children that are parts.

Notes: I’m trying to make a train generator that starts from a locomotive, puts a car behind it, and continues putting cars behind the previous car until a number has been reached. I’ve successfully created the placement mechanism when hard-coded to use a certain axis, but relative positioning hasn’t been successful. I’m trying to use CFrame values instead of Vector3s because they seem to be much more versatile than the latter. CFrame:ToObjectSpace() seems to be for printing and debugging, not for changing position. I’ve successfully matched the orientation of the subsequent cars, yet positioning has been a problem.

1 Like

You need to use the property on the model MoveTo() which accepts cframe
you can read more here!
https://developer.roblox.com/en-us/api-reference/function/Model/MoveTo

Update: Solved problem of models not being cloned correctly, used model:SetPrimaryPartCFrame() before I cloned the object. Now to find out how to do relative positioning.

1 Like

Update Two: I was overcomplicating it. Noticed that CFrame is much simpler than I thought and is already in object space, so I took a more explicit approach.

Code Goal: Move part2 32 studs left of part1 no matter the orientation or position of part2.

cf = part1.CFrame * (CFrame.new(-32, 0, 0))
part2:SetPrimaryPartCFrame(cf)
2 Likes