What I'm doing is making a disco ball and I'm trying to rotate it in the X axis only. I've gotten to do this: game.Workspace.DiscoBall.Rotation = Vector3.new(1,0,0), and so on. How can I loop the rotation to make at least a revolution without having the loop to start over?
for
loops are awesome, and they're just what you need.
for number = 1, 10 do print(number) end
To make a for loop, you start by declaring a variable. In this case I chose number
. Then you give it a number to start at (1) and a number to end at (10). The code in between do
and end
is the code that will keep looping.
A for loop will run for each number between the start and the end numbers.
number
will be increased by 1 every iteration until it equals 10. Then the loop will stop.
As always with coding, the best way to understand is to play with it yourself.
This is pretty easy to apply. There's 360 degrees in a circle, so to make something rotate all the way around we just need a for loop that iterates 360 times.
for rotation = 1, 360 do part.Rotation = Vector3.new(rotation, 0, 0) wait() end
This accounts for one rotation, to do more you just need to put the whole thing in an infinite loop. You can read more about loops on the wiki
Heheh. You never win until you spin! Spin the wheel and select the code you like! That's what I get when I Spin it:
while wait() do Script.Parent.CFrame = Script.Parent.CFrame * CFrame.fromEulerAnglesXYZ(0.040, 0, 0) wait(0.001) end