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

For loop won't work with my button door. Need it for a multistage rocket?

Asked by 8 years ago

Help.

script.Parent.MouseClick:connect(function()
    if script.Parent.Parent.Parent.DOOR.Transparency == 0 then
    for i = 0, 1, 0.1 do
    script.Parent.Parent.Parent.DOOR.Transparency = i
    wait(.01)
    end
    script.Parent.Parent.Parent.DOOR.CanCollide = false
    elseif script.Parent.Parent.Parent.DOOR.Transparency == 1 then
    for i = 1, 0, -0.1 do
    script.Parent.Parent.Parent.DOOR.Transparency = i
    wait(.01)
    end
    script.Parent.Parent.Parent.DOOR.CanCollide = true
    else
    script.Parent.Parent.BrickColor = BrickColor.new("Really red")
    wait(.1)
    script.Parent.Parent.BrickColor = BrickColor.new("Toothpaste")
    end
end)

I'm making a multistage rocket but I need a way for the astronauts to get in. I decided to make a button door rather than setting a brick's cancollide property to false. I want it to fade in and out. I've tried with for loops and it isn't working.

It opens and closes once but doesn't ever again.

0
There is nothing in the output creeper1164 17 — 8y

1 answer

Log in to vote
0
Answered by
AmWrath 41
8 years ago
script.Parent.MouseClick:connect(function()
    if script.Parent.Parent.Parent.DOOR.Transparency == 0 then
    for i = 0, 1, 0.1 do
    script.Parent.Parent.Parent.DOOR.Transparency = i
    wait(.01)
    end
    script.Parent.Parent.Parent.DOOR.CanCollide = false
    elseif script.Parent.Parent.Parent.DOOR.Transparency == 1 then
    for i = 0, 1, -0.1 do
    script.Parent.Parent.Parent.DOOR.Transparency = i
    wait(.01)
    end
    script.Parent.Parent.Parent.DOOR.CanCollide = true
    end
end)

I changed your line 9 and I deleted the else statement. If you put a negative number in a for loop it will automatically count down from the second value. See if this works.

0
This worked but I thought the syntax of a for loop is: for start,stop,step do end Wouldn't it step down from the first number to the second number if the step was negative? creeper1164 17 — 8y
Ad

Answer this question