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

How to make a Door?

Asked by 10 years ago

Please tell me if I press a button that a door will open. How do I do this? Please answer. No stud stuff.

1 answer

Log in to vote
0
Answered by 10 years ago

There are a couple of approaches you can take depending on what you want to do and where you are at in your scripting.

The easiest which ill show you is to simply make the door uncollidable and invisible when you click the button, other ways which can give a nicer effect is to CFrame animate the door or to have it swing on a hinge via a "BodyGyro" but since you don't want "stud stuff" i will leave that for now.

First insert a script into the same model that the door is in and lets make the function that will actually open the door and some variables to keep track of if the door is open or not, try and code this out yourself rather than copy and pasting so that you remember it better.

doorIsOpen = false
door = script.Parent.Door -- change this to where your door is located.
button = script.Parent.Button -- change this to where your button is located.

function OpenOrCloseDoor()
    if doorIsClosed == true then 
        --open the door
        door.CanCollide = true
        door.Transparency = 0   
    else
        -- close the door.  
        door.CanCollide = false
        door.Transparency = 1
    end
end

Then to detect a click you are going to want to use a "ClickDetector" which is in "advanced objects" in roblox studio, go ahead an insert one into the part that you want your button to be in and then add this to our script.

button.ClickDetector.MouseClick:connect(OpenOrCloseDoor)
0
Eh, sorry but I don't get that last bit. Where do I add it in? BritishTea1234 0 — 10y
Ad

Answer this question