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

How to make a door open/close when clicked? [closed]

Asked by 11 years ago

I need to know how to make a door close and open for something I am making..Help?

0
Please read this blog post about asking questions on Scripting Helpers: https://scriptinghelpers.org/blog/posting-good-questions-and-answers-on-scripting-helpers Articulating 1335 — 11y

Closed as Not Constructive by Articulating and evaera

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?

4 answers

Log in to vote
1
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
11 years ago
1local door=script.Parent
2local cd=door:findFirstChild("ClickDetector")or Instance.new("ClickDetector",door)
3cd.MouseClick:connect(function()
4    door.CanCollide=not door.CanCollide
5    door.Transparency=door.CanCollide and 0 or .5
6end)

Turns the door half transparent and lets you walk through it if you click on it when it's closed, turns it solid when you close it. Inserts a ClickDetector if there isn't something named ClickDetector already there.

Ad
Log in to vote
0
Answered by 11 years ago

Trying to make it Cancollide and Transparent?

Log in to vote
0
Answered by 11 years ago

Add a ClickDetector object to the part. Then, in a script in the door, add the following code:

01local door = script.Parent
02local click = door.ClickDetector
03 
04click.MouseClick:connect(function(player)
05    print(player.Name.." clicked the door!")
06    -- Open/close the door, you should probably change this section depending on how the door works
07    if door.CanCollide == true then
08        door.CanCollide = false
09        door.Transparency = 0.9
10    else
11        door.CanCollide = true
12        door.Transparency = 0
13    end
14end)

Again, be sure to alter the code to fit your needs, all that is important is that you know how to open and close the door, and that you know that you use the ClickDetector object and watch for the MouseClick event.

0
Thanks! Ashtonliberty 0 — 11y
Log in to vote
0
Answered by
reaper5 10
11 years ago
01Find = script.Parent:FindFirstChild("ClickDetector")
02if Find==nil then
03Click_Detect = Instance.new("ClickDetector",script.Parent)
04Click_Detect.MaxActivationDistance=8
05else end
06Door = script.Parent
07Door.ClickDetector.MouseClick:connect(function(door)
08Door.CanCollide = not Door.CanCollide
09if Door.CanCollide==false then
10    Door.Transparency=.9
11elseif Door.CanCollide==true then
12    Door.Transparency=0
13end
14end)