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

How do you rotate a model by script? [closed]

Asked by 8 years ago

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.

0
SetPrimaryPartCFrame User#11440 120 — 8y

Locked by JesseSong

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

3 answers

Log in to vote
6
Answered by 6 years ago

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!

0
Definitely did, thanks buddy! Warfaresh0t 414 — 6y
0
this works. much thanks! Austinn_K 31 — 5y
0
i dont know how to set up the model in order for it to work. please teach me how. avatarmik123 0 — 5y
0
To set up a model u need to assign a PrimaryPart in the Model's properties misterviggo 61 — 4y
Ad
Log in to vote
3
Answered by 8 years ago

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))
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. kokungen12345 15 — 8y
0
If you want the model to spin infinitly or whatever, create a loop, or just type "while true do" at the second line. AIphanium 124 — 6y
0
math.rad would also work right? greatneil80 2647 — 6y
Log in to vote
2
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
8 years ago
Edited 8 years ago

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))
0
This doesn't work either. This rotates the model 180 degrees as well. kokungen12345 15 — 8y
1
It doesn't even rotate it for me, its teleporting the model away JadonFrenzy 15 — 6y