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

How do I make a door close after it being opened with a ClickDetector?

I want to make a door open from a click and go transparent, I have that part covered. Though I need help on making it close 1 or 2 seconds after the click. Please help... Below is my code.

Door = script.Parent

function onClicked() Door.Transparency=.6 Door.CanCollide=false end

Door.ClickDetector.MouseClick:connect(onClicked)

if Door.ClickDetector.MouseClick:connect(onClicked) then wait(2) Door.Transparency=0 Door.CanCollide=true end

2 comments

0

There is no code, please edit your question.

0

Oops I forgot, sorry.

1 answer

✓ Accepted answer

I personally can't read random code. Use a code block. You've been here long enough, and I know you've been told this before.

Here's your code in a code block,

Door = script.Parent

function onClicked() 
	Door.Transparency=.6 
	Door.CanCollide=false 
end

Door.ClickDetector.MouseClick:connect(onClicked)

if Door.ClickDetector.MouseClick:connect(onClicked) then 
	wait(2) 
	Door.Transparency=0 
	Door.CanCollide=true 
end

It looks to me like you found a free model, tried to edit it, failed, and came here. Maybe not though. I'm just telling you what it looks like.

Just move the code in the conditional statement into the function "onClicked"

local Door = script.Parent

function onClicked() 
	Door.Transparency=.6 
	Door.CanCollide=false 
	wait(2) 
	Door.Transparency=0 
	Door.CanCollide=true 
end

Door.ClickDetector.MouseClick:connect(onClicked)

Good Luck

If I answered your question, don't forget to click the accept answer button next to this answer.

1 comment

0

Thank you for the help! It worked perfectly. :)

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