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

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

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.

3 comments

0

Use primary part

0

Could you expand please?

0

I tried it and it is just spinning the head of the statue..

1 answer

✓ Accepted answer

##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
    1. 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.
    1. "Workspace" is case sensitive if indexing it from the game, so line 1 needs to be fixed.
    1. 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()

6 comments

0

Okay, thank you so much I just could not figure it out, now I know for the future :)

0

How would I adjust the speed of its rotation?

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

0

So the first option would be increasing the '1' on line 8 to something bigger

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.

1

You can use "RunService.Heartbeat" too; think of it as the RenderStepped version for the Workspace. ;)

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