Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to Cframe a model with multiple parts?

Asked by 7 years ago

First of all, to give you all an idea of my skill level, I would like to say that I'm a beginner. I am not a fresh beginner that I need to read the wiki for more, I already know the basic things.

What exactly is SetPrimaryPartCFrame? If you have a model with multiple parts that you want to cframe rotate (possibly with CFrame.angles) could I use that?

I am making a simple script where you can click a box and it flips open.(Not simple for me, because I made the top lid of the box decorated/multiple parts)

Thanks in advance.

1
SetPrimaryPartCFrame sets the CFrame of the model's PrimaryPart, an ObjectValue under "Model" Change it's CFrame and I believe all its children should change position accordingly. RedneckBane 100 — 7y
1
SetPrimaryCFrame is setting your Primary part of the model, so set your primary part. Then then inside the () you will use GetPrimaryCFrame to get it and move it. papasherms 168 — 7y
0
So in SetPrimaryPartCFrame, does it make all model parts move along with it, or just one part which was set as primary? crystalclay 70 — 7y

1 answer

Log in to vote
3
Answered by
Newrown 307 Moderation Voter
7 years ago
Edited 7 years ago

The wiki is a great place to learn new things, and learning from it does not mean you are a beginner.

To open the lid of a box as you stated above, you will need to make a model of only the parts of the lid, and select any part to become the PrimaryPart of the model by going in the properties of the model and clicking on PrimaryPart, this allows you to set the PrimaryPart.

Now once this step is done, you can use SetPrimaryPartCFrame and GetPrimaryPartCFrame to be able to rotate the model resulting in the lid opening.

SetPrimaryPartCFrame basically moves / rotates the primary part according to the CFrame assigned to it and keeps the orientation and offset of all the parts inside the model.

GetPrimaryPartCFrame returns the current CFrame of the primary part of the model

Code:

local model = script.Parent

model:SetPrimaryPartCFrame(model:GetPrimaryPartCFrame() * CFrame.Angles(0, 0, math.rad(45)) -- assuming you want it to rotate 45 degrees on the z-axis

Hope it helped!

0
It worked, thank you so much! Oops, I misworded that- I meant to specify that I didn't need to master intro to scripting, the wiki is indeed for everyone. Thank you all for your help! crystalclay 70 — 7y
0
Happy it helped :) Newrown 307 — 7y
Ad

Answer this question