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.
How do you rotate a model by script?
3 answers
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
Definitely did, thanks buddy!
this works. much thanks!
i dont know how to set up the model in order for it to work. please teach me how.
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
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.
If you want the model to spin infinitly or whatever, create a loop, or just type "while true do" at the second line.
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
This doesn't work either. This rotates the model 180 degrees as well.
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.

1 comment
SetPrimaryPartCFrame