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

How do I make a script that opens a door

Asked by 10 years ago

So that once you click the door knob, it opens the door. What are the procedures to connecting all the bricks as well to make them all move once you open it?

2 answers

Log in to vote
1
Answered by
Damo999 182
10 years ago

Well you would need to use a ClickDetector which you would put inside of the door knob after that you would inset a script into the door knob and the code would look something like this. You might want to weld the knob to the door so that the knob will move with the door.

knob = script.Parent  --The name of the part the script is in
door = script.Parent.Parent.door --the name of the part you want to open
c = Instance.new("ClickDetector",knob) -- adding a clickdetector to it.

function onClick()
    knob.CFrame = knob.CFrame *CFrame.Angles(0,0,1) --changed the position of the door on the z axis

end
knob.ClickDetector.MouseClick:connect(onClick) -- connect it and done

Ad
Log in to vote
1
Answered by 10 years ago

This script requires the Door and the Handle (Knob as you chose to call it) to be in a group together.

local Handle=script.Parent 
local Door=Handle.Parent.Door --Door part must be called 'Door'
local = Clicker = Instance.new("ClickDetector", Handle)

function onClick()
Handle.Transparency=1
Door.Transparenc =1
wait(5)
Handle.Transparency=0
Door.Transparency 0
end
Clicker.MouseClick:connect(onClick()
--Hope it helps

Answer this question