Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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.

1 comment

0

There is nothing in the output

1 answer

✓ Accepted answer
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.

1 comment

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?

This discussion is preserved as it was. New answers, comments, and votes are closed.