I need to know how to make a door close and open for something I am making..Help?
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.
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.
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)
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?