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

How would I rotate an entire model forever? Here is what I have, I'm never used CFrame.

Asked by 7 years ago

I have never used CFrame, and I have tried multiple ways of doing this and I just can not figure it out, here is what I have

local model = game.workspace.smallStatue

function rotateMod()
    for i=1,360 do
        model.CFrame = model.CFrame * CFrame.fromEulerAnglesXYZ(0,0,0)
    end
end

rotateMod()

Sorry, I'm completely clueless. Thanks.

0
Use primary part dovydas12345 15 — 7y
0
Could you expand please? GuestRealization 102 — 7y
0
I tried it and it is just spinning the head of the statue.. GuestRealization 102 — 7y

1 answer

Log in to vote
2
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
7 years ago

What you need

You're on the right track, but there are a few issues.

  • 1) Models don't have a CFrame property, so you're going to have to take advantage of the GetPrimaryPartCFrame and SetPrimaryPartCFrame functions. These functions get and set the CFrame of the model according to the model's PrimaryPart location. Note: you will have to set the PrimaryPart property prior to using either of these functions

  • 2) In order to effectively rotate a CFrame, you should use the CFrame.Angles constructor. Remember to put in radians as arguments aswell, using the math.rad function.

  • 3) "Workspace" is case sensitive if indexing it from the game, so line 1 needs to be fixed.

  • 4) Your for loop needs a wait in it, otherwise this will happen instantaneously.


Code

local model = workspace.smallStatue

function rotateMod()
    model.PrimaryPart = model:GetChildren()[1] --Set the PrimaryPart
    for i = 1,360 do
        local cf = model:GetPrimaryPartCFrame() --Get the current CFrame
        --Set the CFrame relative to current cf, rotated by 1 radian
        model:SetPrimaryPartCFrame(cf * CFrame.Angles(math.rad(1),0,0))
        wait() --yield
    end
end

rotateMod()
0
Okay, thank you so much I just could not figure it out, now I know for the future :) GuestRealization 102 — 7y
0
How would I adjust the speed of its rotation? GuestRealization 102 — 7y
1
No problem :D Glad I could help. If you want to adjust the speed you can either increase the increment it rotates on each iteration, or decrease the yield in between iterations Goulstem 8144 — 7y
0
So the first option would be increasing the '1' on line 8 to something bigger Goulstem 8144 — 7y
View all comments (2 more)
0
Second option would be using game:GetService("RunService").RenderStepped:Wait() from a LocalScript as the yield, to replace line 9. First option is preferable unless you plan on keeping the model on the client, or in the camera. Goulstem 8144 — 7y
1
You can use "RunService.Heartbeat" too; think of it as the RenderStepped version for the Workspace. ;) TheeDeathCaster 2368 — 7y
Ad

Answer this question