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

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

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

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)


3 comments

0

Sorry, the code didn't format correctly.

0

thats ok, thanks btw

0

You can edit your answers :)

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