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

Elseif doesn't work with my animation script?

Asked by 5 years ago
Edited 5 years ago

I'm trying to make an animation script, and I use a GUI to control the animations. Is this problem because elseif is broken or is it something wrong with my code?

For the ON Script:

local btn = script.Parent
local plane = workspace.EmbraerE190
local thruster1 = plane.MOTOR1.Motor
local thruster2 = plane.MOTOR4.Motor
local thruster3 = plane.MOTOR5.Motor
local thruster4 = plane.MOTOR6.Motor





function MoveIt()
    if thruster1.DesiredAngle == 0 then
        thruster1.DesiredAngle = 0.05
        thruster2.DesiredAngle = 0.05
        thruster3.DesiredAngle = 0.05
        thruster4.DesiredAngle = 0.05
        script.Parent.Parent.Off.Visible = true
        script.Parent.Parent.Off.Active = true
        print 'changed to .05'
    elseif thruster1.DesiredAngle == 0.05 then
        thruster1.DesiredAngle = 0.1
        thruster2.DesiredAngle = 0.1
        thruster3.DesiredAngle = 0.1
        thruster4.DesiredAngle = 0.1
        print 'changed to .1'
    elseif thruster1.DesiredAngle == 0.1 then
        thruster1.DesiredAngle = 0.15
        thruster2.DesiredAngle = 0.15
        thruster3.DesiredAngle = 0.15
        thruster4.DesiredAngle = 0.15
        print 'changed to .15'
    elseif thruster1.DesiredAngle == 0.15 then
        thruster1.DesiredAngle = 0.2
        thruster2.DesiredAngle = 0.2
        thruster3.DesiredAngle = 0.2
        thruster4.DesiredAngle = 0.2
        script.Parent.Active = false
        script.Parent.Visible = false
        print 'changed to .2'   

end
end

btn.MouseButton1Click:Connect(MoveIt)








For the OFF script:

local btn = script.Parent
local plane = workspace.EmbraerE190
local thruster1 = plane.MOTOR1.Motor
local thruster2 = plane.MOTOR4.Motor
local thruster3 = plane.MOTOR5.Motor
local thruster4 = plane.MOTOR6.Motor





function MoveIt()
    if thruster1.DesiredAngle == 0.05 then
        thruster1.DesiredAngle = 0
        thruster2.DesiredAngle = 0
        thruster3.DesiredAngle = 0
        thruster4.DesiredAngle = 0
        script.Parent.Active = false
        script.Parent.Visible = false
        print 'changed to 0'    
    elseif thruster1.DesiredAngle == 0.1 then
        thruster1.DesiredAngle = 0.05
        thruster2.DesiredAngle = 0.05
        thruster3.DesiredAngle = 0.05
        thruster4.DesiredAngle = 0.05
        print 'changed to .05'
    elseif thruster1.DesiredAngle == 0.15 then
        thruster1.DesiredAngle = 0.1
        thruster2.DesiredAngle = 0.1
        thruster3.DesiredAngle = 0.1
        thruster4.DesiredAngle = 0.1
        print 'changed to .1'
    elseif thruster1.DesiredAngle == 0.2 then
        thruster1.DesiredAngle = 0.15
        thruster2.DesiredAngle = 0.15
        thruster3.DesiredAngle = 0.15
        thruster4.DesiredAngle = 0.15
        script.Parent.Parent.On.Visible = true
        script.Parent.Parent.On.Active = true
        print 'changed to .15'

end
end

btn.MouseButton1Click:Connect(MoveIt)








Help is appreciated!

1 answer

Log in to vote
1
Answered by 5 years ago

I don't see the problem with using else if in your case but there's a thing with lua when sometimes when using == to some number doesn't work as expected.

The thing is, you are tring to compare a number for example with 0.5. However the property you are checking can be just rounded to 0.5 but actually is 0.49999 or something like that.

So what you could use is to check if something is bigger than say 0.49 and smaller than 0.51. And do the same with every else if check.

--example
if property > 0.49 and property < 0.51 then
    --checking if it's 0.5
end

Now I don't know if I explained it correctly or if you can really understand but it should fix your problem, cause I had something similar once.

Correct me if I'm wrong tho.

0
I'll try Syntax_404 37 — 5y
Ad

Answer this question