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
7 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.

01Button = script.Parent.Button
02Door  = script.Parent.Door
03IsOpen = false
04 
05function clicked()
06    if IsOpen == false then
07        Button.BrickColor = BrickColor.Green()
08        for i = 0, 1, 0.1 do
09            wait()
10            Door.Transparency = i
11            Door.CanCollide = false
12        end
13        IsOpen = true
14    elseif IsOpen == true then
15        Button.BrickColor = BrickColor.Red()
View all 25 lines...

1 answer

Log in to vote
2
Answered by 7 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 — 7y
0
thats ok, thanks btw Duksten 20 — 7y
0
You can edit your answers :) Goulstem 8144 — 7y
Ad

Answer this question