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

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

Asked by 7 years ago
Edited 7 years ago

Please include the code which you are trying to use, so the community will be better-equipped to help you with your problem.

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

0
There is no code, please edit your question. EzraNehemiah_TF2 3552 — 7y
0
Oops I forgot, sorry. ReynaldoVictarion 70 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

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.
0
Thank you for the help! It worked perfectly. :) ReynaldoVictarion 70 — 7y
Ad

Answer this question