My value / repeat script that spins a motor turns on, but only keeps turning on and the motor spins faster. I have tried using a number value but it still will not work. I don't know if it is the repeat scripts that are interfering but here is the script for anybody who is willing to help:
local main = script.Parent.Main local switches = script.Parent.Switches local engine = script.Parent.Engine switches.Click.ClickDetector.MouseClick:Connect(function(Spin) local State = 0 if State == 0 then switches.On.Transparency = 0 switches.Off.Transparency = 1 State = 0 for On = 1, 5 do wait(0.5) engine.HingeConstraint.AngularVelocity = engine.HingeConstraint.AngularVelocity + 1 end else switches.On.Transparency = 1 switches.Off.Transparency = 0 State = 0 for Off = 1, 5 do wait(0.5) engine.HingeConstraint.AngularVelocity = engine.HingeConstraint.AngularVelocity - 1 end end end)
Any help appreciated! :)
Just found out that because the "local state = 0" (on line 6) is inside the function, it will not work! By putting the local outside the function it then works! here is what i mean:
local main = script.Parent.Main local switches = script.Parent.Switches local engine = script.Parent.Engine local value = 0 switches.Click.ClickDetector.MouseClick:Connect(function(Spin) if value == 0 then switches.On.Transparency = 0 switches.Off.Transparency = 1 value = 1 for On = 1, 5 do wait(0.5) engine.HingeConstraint.AngularVelocity = engine.HingeConstraint.AngularVelocity + 1 end else switches.On.Transparency = 1 switches.Off.Transparency = 0 value = 0 for Off = 1, 5 do wait(0.5) engine.HingeConstraint.AngularVelocity = engine.HingeConstraint.AngularVelocity - 1 end end end)
PS - (i moved it from line 6 to line 4 that's the difference because line 4 is not inside the function whereas line 6 is!)