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

I cant figure out why my door script won't close the door, any suggestions?

Asked by
Duksten 20
6 years ago

I am making a script that uses a click detector to close and open a door. I used a for loop to make the door closing/opening look more smoother. The script is fine when it comes to opening the door, however the second part of the function, which allows for the closing of the door does not work. The button color does not change and stays at green, and the door does not close.

Button = script.Parent.Button
Door  = script.Parent.Door
IsOpen = false

function clicked()
    if IsOpen == false then
        Button.BrickColor = BrickColor.Green()
        for i = 0, 1, 0.1 do
            wait()
            Door.Transparency = i
            Door.CanCollide = false
        end
        IsOpen = true
    elseif IsOpen == true then
        Button.BrickColor = BrickColor.Red()
        for i = 1, 0, 0.1 do
            wait()
            Door.Transparency = i
            Door.CanCollide = true
        end
        IsOpen = false
    end
end

Button.ClickDetector.MouseClick:connect(clicked)

1 answer

Log in to vote
2
Answered by 6 years ago

Your second for loop is trying to count from 1 to 0 by adding .1. You need to subtract .1. Here's the new code. ~~~~~~~~~~~~~~~~~ Button = script.Parent.Button Door = script.Parent.Door IsOpen = false

function clicked() if IsOpen == false then Button.BrickColor = BrickColor.Green() for i = 0, 1, 0.1 do wait() Door.Transparency = i Door.CanCollide = false end IsOpen = true elseif IsOpen == true then Button.BrickColor = BrickColor.Red() for i = 1, 0, -0.1 do wait() Door.Transparency = i Door.CanCollide = true end IsOpen = false end end

Button.ClickDetector.MouseClick:connect(clicked)

~~~~~~~~~~~~~~~~~

0
Sorry, the code didn't format correctly. Bluemonkey132 194 — 6y
0
thats ok, thanks btw Duksten 20 — 6y
0
You can edit your answers :) Goulstem 8144 — 6y
Ad

Answer this question