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

How do you rotate a model by script?

To rotate a model by script in roblox studio is probably very simple. But I havn't been able to do it. So my qustion is how to rotate a model by script. Do you use CFrame? I'm pretty new to roblox lua.

1 comment

0

SetPrimaryPartCFrame

3 answers

✓ Accepted answer

i know this thread is old but i think other people would get helped if this got resolved, to rotate it you can almost use BlackJPIs script just a small change

local cframe = model.PrimaryPart.CFrame -- Current CFrame

model:SetPrimaryPartCFrame(cframe * CFrame.Angles(0, math.rad(90), 0))

Like you see its only the CFrame.new thing ive changed to CFrame.Angles, when you make .new it will make a new CFrame position and Angles will put its orientation, hope some people have use of this!

4 comments

0

Definitely did, thanks buddy!

0

this works. much thanks!

0

i dont know how to set up the model in order for it to work. please teach me how.

0

To set up a model u need to assign a PrimaryPart in the Model's properties

The best way to rotate a model is by using the SetPrimaryPartCFrame function.

It will take a model and rotate it around its PrimaryPart. Note that you will have to set that before using it, or you'll see an error. You can do that in the Properties window.

For example, this will rotate the model 90 degrees along its Y axis:

local Model = workspace.Model -- Replace this with your model.

Model:SetPrimaryPartCFrame(CFrame.new(0, math.deg(90), 0))

3 comments

0

This didn't really work. This turns it 180 degrees and it always does, even if I put something else in the math.deg() paranteces.

0

If you want the model to spin infinitly or whatever, create a loop, or just type "while true do" at the second line.

0

math.rad would also work right?

IDidMakeThat has the correct procedure but has some errors in his implementation.

He is setting the PrimaryPart's CFrame to the position (0, 5156.62, 0). Also, math.deg takes an argument in radians and gives you that value in degrees. So you'll want to use math.rad.

Examples

This example will rotate the model by a given amount from its current position:

local cframe = model.PrimaryPart.CFrame -- Current CFrame
model:SetPrimaryPartCFrame(cframe * CFrame.new(0, math.rad(90), 0))

This example will set the model's rotation instead of rotating from its current position:

local cframe= CFrame.new(model.PrimaryPart.Position) -- CFrame with default rotation
model:SetPrimaryPartCFrame(cframe * CFrame.new(0, math.rad(90), 0))

2 comments

0

This doesn't work either. This rotates the model 180 degrees as well.

1

It doesn't even rotate it for me, its teleporting the model away

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