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

How do I make a part rotate constantly while game is running using CFrame?

So, I've got the hang of moving parts using CFrame, but how do I use CFrame to rotate parts? Basically, I have a half-done script where using a while loop, I make a part rotate. Here's the script:

local part = script.Parent
local start = part.CFrame

while wait(0.000001) do
	part.CFrame = start + CFrame.Rotation
end

I know I probably did something wrong so far, and I also don't know how to finish it. All help is appreciated!

1 answer

✓ Accepted answer

To rotate parts with CFrame, you have to multiply that part's CFrame by something called CFrame.Angles. For example:

local part = game.Workspace.Part
part.CFrame = part.CFrame * CFrame.Angles(0,1,0)

The part's CFrame will be rotated by 1 radian on the y-axis. It's complicated at first, but you get the hang of it. For more information on CFrame, read this: http://wiki.roblox.com/index.php?title=CFrame

If you want to repeat this forever, use a while loop.

while true do
part.CFrame = part.CFrame * CFrame.Angles(0,1,0)
end

And it seems like you want to wait 0.000001 seconds, which is pretty much just wait(), but in this example, I'll use 1.

while true do
part.CFrame = part.CFrame * CFrame.Angles(0,1,0)
wait(1)
end

I hope this helped.

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