Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How should I move ALL parts in a model using CFrame?

I have a script which clones vehicle models from ServerStorage and puts them in factory's around the map. The only problem is that I have been using MoveTo: to re position the vehicles, and in one factory they spawn on the roof (probably because of an invisible and CanCollide false part or something) I thought the solution would be simple:

Vehicle.PrimaryPart.CFrame = FactoryBase.CFrame + Vector3.new(0,10,0)

I also thought always having the right rotation would be nice too. However, only the body of the vehicle teleports to this position, not the wheels, (which are attached via spring constraints and prismatic constraints.) This results in the car and the wheels flying towards each other and sometimes glitching out or sandwiching walls and other vehicles. I think the fact that the wheels aren't welded to the car could be the reason that they do not move with the vehicle. Is there a form of MoveTo: that ignores other parts or a way to get CFrame to move all the Vehicle's parts? If so I really need to know.

Thanks

1 comment

0

v v v poke

1 answer

✓ Accepted answer

Set a primary part to the model (Model.PrimaryPart = BasePart Instance in model), and then use Model:SetPrimaryPartCFrame(CFrame) to relocate the entire model based on the position offsets of the primery part.

3 comments

0

Does the line Model:SetPrimaryPartCFrame() differ from Mode.PrimaryPart.CFrame = ()? If so that's great!

0

Yes. Model.PrimaryPart.CFrame would return (Model.PrimaryPart).CFrame, which would only update that part. Using SetPrimaryPartCFrame uses some behind the scenes magic from roblox to relocate every part to the correct offset on the new CFrame.

0

thank you this really helps!

This discussion is preserved as it was. New answers, comments, and votes are closed.