I am trying to make a script that if the tool touches the sensor and its name is Economy, it sets the Desired Angle of the motor to rotate 1.6. Thing is, its not rotating!
My script:
local WaitingTime = 2 --Time the Gate stays open
local open = false
function OpenGate()
if not open then
open = true
script.Parent.Parent.Gate.D1.Motor.DesiredAngle = 1.6
script.Parent.Parent.Gate.D2.Motor.DesiredAngle = 1.6
wait(WaitingTime)
open = false
script.Parent.Parent.Gate.D1.Motor.DesiredAngle = 0
script.Parent.Parent.Gate.D2.Motor.DesiredAngle = 0
end
end
script.Parent.Touched:Connect(function(hit)
if hit.Parent.Name == "Economy" then
OpenGate()
end
end)
When I tested it in game, the motors Desired Angle chnaged but the actual part didnt move.
Its not the issue that the desired angle doesnt get set, its the part doesnt move. After the script activates, if you look at the motor in explorer, the desired angle was set. The part just doesnt move after the angle is set.
Because DesiredAngle is just a value it tries to achieve. CurrentAngle is the real value and it will try to move the Part2 with the set MaxVelocity.
Motors are kinda old and I have no idea if they act the same way as Welds and Motor6Ds when DesiredAngle is changed. You might need to fire the SetDesiredAngle method for it to try to achieve the target.
Also, please reply to messages instead of the topic. Only noticed your reply after checjing scripting support again as I get no notifications
To test what @nooneisback is saying about utilizing Max Velocity, use this script. I don’t play with Motors enough to know if this is gonna move fast or slow or what, but let us know the results. See if the gate moves at all.
For future reference though, using HingeConstraints is much easier, and as they push more of the PGS physics being utilized all throughout Roblox, HingeConstraints will become standard over using Motors.
local WaitingTime = 2 --Time the Gate stays open
local open = false
function OpenGate()
if not open then
open = true
script.Parent.Parent.Gate.D1.Motor.DesiredAngle = 1.6
script.Parent.Parent.Gate.D2.Motor.DesiredAngle = 1.6
script.Parent.Parent.Gate.D1.Motor.MaxVelocity = 1
script.Parent.Parent.Gate.D2.Motor.MaxVelocity = 1
wait(WaitingTime)
open = false
script.Parent.Parent.Gate.D1.Motor.DesiredAngle = 0
script.Parent.Parent.Gate.D2.Motor.DesiredAngle = 0
script.Parent.Parent.Gate.D1.Motor.MaxVelocity = 1
script.Parent.Parent.Gate.D2.Motor.MaxVelocity = 1
end
end
script.Parent.Touched:Connect(function(hit)
if hit.Parent.Name == "Economy" then
OpenGate()
end
end)
Was just about to say that, I was reading through the Motor API and saw now there is a function for setting the angle.
local WaitingTime = 2 --Time the Gate stays open
local open = false
function OpenGate()
if not open then
open = true
script.Parent.Parent.Gate.D1.Motor:SetDesiredAngle(1.6)
script.Parent.Parent.Gate.D2.Motor:SetDesiredAngle(1.6)
script.Parent.Parent.Gate.D1.Motor.MaxVelocity = 1
script.Parent.Parent.Gate.D2.Motor.MaxVelocity = 1
wait(WaitingTime)
open = false
script.Parent.Parent.Gate.D1.Motor:SetDesiredAngle(0)
script.Parent.Parent.Gate.D2.Motor:SetDesiredAngle(0)
script.Parent.Parent.Gate.D1.Motor.MaxVelocity = 1
script.Parent.Parent.Gate.D2.Motor.MaxVelocity = 1
end
end
script.Parent.Touched:Connect(function(hit)
if hit.Parent.Name == "Economy" then
OpenGate()
end
end)
The section you want to start from is “Hinge Front Wheels to Base”
You’d setup the HingeConstraint exactly like shown in those diagrams, and then you’d call them in your script, like you did for the motor. Instead of
Motors are done in Radians though, and HingeConstraints are done in Degrees.
So your 1.6 Radians is roughly 91 degrees. (Hence the numbers in the examples.)
You’re welcome! And like I was saying, Motors are apart of SurfaceWelding which is something they’re looking to phase out over time.
HingeConstraints however is what Roblox is pushing for, for the future. So you’re already setup on the right path and shouldn’t need to keep tweaking it over time.
If that’s the solution to your problem and you’re all set, don’t forget to mark whatever comment helped you obtain the answer with the solution button to make sure others coming to this thread know you’ve been helped and can quickly get to the solution if they have the same problem.