How to Open a Door When Clicking a Button
Download – Door Model and Script
How To – Open a Door When Clicking a Button in Roblox Studio
What’s up everyone, BuzzyBeth here – In this tutorial we’ll be learning how to open a door when clicking a button!
- Inside of our workspace let’s go ahead and spawn in a part and then let’s rename that to “door”.
- Next up let’s go ahead and create a duplicate of our door part and then let’s move it up so that it’s directly above our door part. Then of course let’s go ahead and rename that part to “EndPos” short for end position. Set the transparency of it to one.
- Now create our button that we want to click to open the door. I’m just going to go ahead and create a simple button and then create a little red part on top of it so that people know they are supposed to click on this red part.
- For this red part, I just want to make sure to rename that to “button” because I will be referencing this inside of my script in just a second.
- Highlight all of our parts and then group them inside of a model. So we have a button inside of our model, a door, the end position part which is transparent, and a part that just belongs with the button but we have no use for this part.
- Add an intvalue and then rename this intvalue to “time” and then set the value to whatever you want i’m going to set it to two. It just means that it takes two seconds for the door to open and close.
- Add a script inside of our model and let’s add a click detector inside of our button.
- So with this script it’ll look a little bit familiar to a previous script that we’ve used for a door model and we’re actually just going to be adding a function so that we’ll be able to use our click detector!
- We’re going to go ahead and set our variables which references our entire model, the end position part, our actual door part, our button, the clickdetector a debounce, as well as a tweenservice.
- We’re gonna go ahead and set the tween information, for the time since we already added an intvalue we’re going to go ahead and do model.time.value and we’re going to set our easing style to sine, the easing direction to out. We don’t want our tween to repeat, but we do want our part to reverse and then no delays
- Create a function and on mouse click function where if not activated then our debounce is going to be equal to true
- Set our tween information where the door is going to open all the way up until it reaches the end position part. It’s going to wait until that task is finished and then it’s going to reverse. Then the debounce is going to equal to false and then we’re going to go ahead and call our function.