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

How would I make a motor continuously spin?

Asked by
ultrabug 306 Moderation Voter
8 years ago

Basically I am making a rotor, you press the button and a motor object makes the rotor head rotate in the left or right direction. I would like for the motor to rotate continuously, but after a while it stops.

01local base=script.Parent
02local spinny = script.Parent.Parent.Spinny
03local speed=(((math.pi*2)/60)/2)
04local bl= script.Parent.Parent.ButtonLeft
05local br=script.Parent.Parent.ButtonRight
06local right=false
07local left=false
08local runningc=script.Parent.Parent.Running
09local offc=script.Parent.Parent.Off
10 
11local motor=Instance.new("Motor", base)
12motor.Part0=base
13motor.Part1=spinny
14motor.MaxVelocity=speed
15motor.C0=CFrame.new(0, 0, -2.5)
View all 54 lines...

Thanks for any help.

1
you got any loops? and maybe try a "repeat until" loop. So it repeats spining or whatever till the button is clicked to turn it off sammiya1 134 — 8y
0
Commenting because I scripted a motor to test this and I encountered the same problem. I did lots of googling and searching for help on this issue but couldn't find any. I'm also trying to solve this! Will update if I find anything useful patrline5599 150 — 8y
1
I will try the loop idea out. Also maybe to help with the testing, I notice that if you increase the ammount that you add to the desiredangle, it increases how long the motor will continue to spin. I tried math.huge, but then it didn't work at all. ultrabug 306 — 8y

1 answer

Log in to vote
0
Answered by
camxd01 48
8 years ago

Though I am not the best scripter, I can guide you here. First you must have 2 different variables that are equal to 0 Ex:

1local StopSpinning = 0
2local Rotate = 0

Note:*Or you can just use i = 0 for StopSpinning * Next you must have a repeat loop like sammiya suggested. ( X = your item you want to spin)

1repeat
2X.Rotation = Vector3.new( 00, 0)--Change the axis you want it to spin on to your "Rotate" variable.
3wait(.01)
4Rotate = Rotate + 3
5until StopSpinning == 1

Rotation directions: In X spot: Like a rolling wheel In Y spot: Like a top or a jack In Z spot: Flips like a coin in the air or you can make put Rotate in several directions to make it unique. You can set the off button to make StopSpinning (or i) to 1.

If you have more than 1 loop, it will not work unless you use Coroutine Ex:

01local TheRotateLoop = coroutine.wrap(function()
02    repeat
03coin.Rotation = Vector3.new( 0, 0, a)
04wait(.01)
05a = a+3
06until staph == 1
07end)
08local TheSecondLoop = coroutine.wrap(function()
09--Stuff
10end)
11 
12 
13TheRotateLoop()
14TheSecondLoop()

You can add more loops by copying a loop and and putting it at the bottom so it runs like the others.

Hope it works, if it does, please feel free to ask questions if you have them and upvote ;3

Ad

Answer this question