I made this very simple script. when the go button is clicked, go, and stop when the stop button is pressed. The click detectors and buttons work because when I click them, the sound plays. But the motor doesn’t do anything.
local stop = script.Parent.Controls.stop.ClickDetector
local start =script.Parent.Controls.start.ClickDetector
local L1 = script.Parent.Controls["1"].ClickDetector
local L2 = script.Parent.Controls["2"].ClickDetector
local L3 = script.Parent.Controls["3"].ClickDetector
local Motor = script.Parent.Spinnything.bottom.HingeConstraint
local clunk= script.Parent.Controls.start.clunk
local startup= script.Parent.Controls.start.start
local buzzerstop= script.Parent.Controls.stop.buzzer
local buzzer= script.Parent.Controls.start.Sound
local shutdown=script.Parent.Controls.stop.Sound
function cow() -- Stop the motor
buzzerstop:Play()
wait(1)
Motor.AngularSpeed= 50
shutdown:Play()
wait(1)
end
function pig() -- start the motor
buzzer:Play()
wait(1)
Motor.AngularSpeed = 300
startup:Play()
end
function sheep() --level 1
Motor.AngularSpeed=15000
end
function horse() --level 2
Motor.AngularSpeed= 33333
end
function chicken() -- level 3
Motor.AngularSpeed= 50000
end
stop.MouseClick:connect(cow)
start.MouseClick:connect(pig)
L1.MouseClick:connect(sheep)
L2.MouseClick:connect(horse)
L3.MouseClick:connect(chicken)
I changed your script slightly, so you don’t use so many functions, but rather have one that manages everything. As far as the actual motor goes, you can help yourself by using print statements. Check where the code stops. Does it even stop? To me, it seems like you don’t have your parts unanchored. HingeConstraints, as well as BodyMovers, require parts to be unanchored. Only those parts can have their physics simulated. In your case, I can imagine you having some kind of a spinning part (e.g. propeller). HingleConstraints require two attachments: one inside the unanchored part and one inside an anchored root.
I didn’t test the following code, so there is a small possibility that you’ll get an error in the first run, but I’m sure you will easily correct the mistake.
local path = script.Parent.Controls
local start = path.start.ClickDetector
local stop = path.stop.ClickDetector
local L1 = path["1"].ClickDetector
local L2 = path["2"].ClickDetector
local L3 = path["3"].ClickDetector
local Motor = script.Parent.Spinnything.bottom.HingeConstraint
local clunk = path.start.clunk
local startup = path.start.start
local buzzerstop = path.stop.buzzer
local buzzer = path.start.Sound
local shutdown = path.stop.Sound
local motorLevels = {
["cow"] = 50;
["pig"] = 300;
["sheep"] = 15000;
["horse"] = 33333;
["chicken"] = 50000;
}
local function runMotor(level)
if (level == "cow") then -- motor stop
buzzerstop:Play(); wait(1)
Motor.AngularVelocity = motorLevels[level]
shutdown:Play(); wait(1)
return;
elseif (level == "pig") then -- motor start
buzzer:Play(); wait(1)
Motor.AngularVelocity = motorLevels[level]
startup:Play()
return;
end
Motor.AngularVelocity = motorLevels[level]
end
start.MouseClick:Connect(function() runMotor("pig") end)
stop.MouseClick:Connect(function() runMotor("cow") end)
L1.MouseClick:Connect(function() runMotor("sheep") end)
L2.MouseClick:Connect(function() runMotor("horse") end)
L1.MouseClick:Connect(function() runMotor("chicken") end)
EDIT. Make sure MaxTorque propery of HingeConstraint is a high value.
EDIT 2. @hugtrain my bad, it’s not AngularSpeed but AngularVelocity to be changed. Try running the above script and message me privately in case it still doesn’t work. AngularSpeed is a property used when working with servo actuator type.