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 10 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 — 10y

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
10 years ago
local door=script.Parent
local cd=door:findFirstChild("ClickDetector")or Instance.new("ClickDetector",door)
cd.MouseClick:connect(function()
    door.CanCollide=not door.CanCollide
    door.Transparency=door.CanCollide and 0 or .5
end)

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 10 years ago

Trying to make it Cancollide and Transparent?

Log in to vote
0
Answered by 10 years ago

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

local door = script.Parent
local click = door.ClickDetector

click.MouseClick:connect(function(player)
    print(player.Name.." clicked the door!")
    -- Open/close the door, you should probably change this section depending on how the door works
    if door.CanCollide == true then
        door.CanCollide = false
        door.Transparency = 0.9
    else
        door.CanCollide = true
        door.Transparency = 0
    end
end)

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 — 10y
Log in to vote
0
Answered by
reaper5 10
10 years ago
Find = script.Parent:FindFirstChild("ClickDetector")
if Find==nil then
Click_Detect = Instance.new("ClickDetector",script.Parent)
Click_Detect.MaxActivationDistance=8
else end
Door = script.Parent
Door.ClickDetector.MouseClick:connect(function(door)
Door.CanCollide = not Door.CanCollide
if Door.CanCollide==false then
    Door.Transparency=.9
elseif Door.CanCollide==true then
    Door.Transparency=0
end
end)