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

How would I make a motor continuously spin?

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.



local base=script.Parent
local spinny = script.Parent.Parent.Spinny
local speed=(((math.pi*2)/60)/2)
local bl= script.Parent.Parent.ButtonLeft
local br=script.Parent.Parent.ButtonRight
local right=false
local left=false
local runningc=script.Parent.Parent.Running
local offc=script.Parent.Parent.Off

local motor=Instance.new("Motor", base)
motor.Part0=base
motor.Part1=spinny
motor.MaxVelocity=speed
motor.C0=CFrame.new(0, 0, -2.5)
--                  -z  -x, -y

bl.ClickDetector.MouseClick:connect(function()
	if left==false then
		left=true
		right=false
		bl.BrickColor= runningc.Value
		br.BrickColor= offc.Value
	elseif left==true then
		left=false
		right=false
		bl.BrickColor=offc.Value
		br.BrickColor=offc.Value
	end
end)

br.ClickDetector.MouseClick:connect(function()
	if right==false then
		right=true
		left=false
		br.BrickColor= runningc.Value
		bl.BrickColor= offc.Value
	elseif right==true then
		left=false
		right=false
		bl.BrickColor=offc.Value
		br.BrickColor=offc.Value
	end
end)
while true do
	wait()
	if left==true then
		motor.DesiredAngle=motor.CurrentAngle + math.rad(10)
	elseif right==true then
		motor.DesiredAngle=motor.CurrentAngle - math.rad(10)
	else
		motor.DesiredAngle=motor.CurrentAngle		
	end
end


Thanks for any help.

3 comments

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

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

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.

1 answer

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:

local StopSpinning = 0
local 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)

repeat
X.Rotation = Vector3.new( 0,  0, 0)--Change the axis you want it to spin on to your "Rotate" variable.
wait(.01)
Rotate = Rotate + 3
until 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:

local TheRotateLoop = coroutine.wrap(function()
    repeat
coin.Rotation = Vector3.new( 0, 0, a)
wait(.01)
a = a+3
until staph == 1
end)
local TheSecondLoop = coroutine.wrap(function()
--Stuff
end)

 
TheRotateLoop()
TheSecondLoop()

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

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