Roblox Heist: Sliding Doors

Step 1
In this lesson we will made a pair of sliding doors and learn to use Tweening to make smooth movements
Step 2
Start by constructing some doors, walls, and a button (All out of cubes)

The doors will slide into the walls, so make sure the walls are wider and longer


You MUST name your doors and the button

Step 3
Add an empty Model to the Workspace

Name this model something like Front Doors

Step 4
Drag and drop each piece of your sliding doors into "Front Doors"

Like this

Step 5
We need to write a script that will move each door 5 studs to the left or right once the button is clicked

First we need a way to Detect if our Button is clicked

Step 6
Add a ClickDetector object to the button
Step 7
Set the maximum activation distance for the button to around 10

This is how close the player must be in order to click the button

Step 8
Now add a script to the button and name is "OpenDoors"
Step 9
Create references to the button, the doors, and the clickDetector

We can find the doors by using button.Parent

(which is the Front Doors Model):

Step 10
Create a function named "openDoors" and connect it to the MouseClick event of clickDetector
Step 11
For now, have this function simply print to the output window
Check Your Work
Step 12
You should be able to click the button, but only if you are close enough, and have it output "Opening Doors"
Step 13
Now we'll replace the print statement with moving the door to its "open" position

The Open position will be: (the doors position) + (5 studs to the right)


We need to be a little fancy to define "5 studs to the left"

CFrames are basically door's orientation and thus can tell us which way is to its "right"

Check Your Work
Step 14
Now, the door will move to the right but it will go into the wall and the collision will push it up...

We can fix this by turning off collision when the door is opened

Step 15
Turn off CanCollide when the door is opened by setting it to false
Check Your Work
Step 16
Now the door should open correctly

...and I'm freee!

Step 17
Now see if you can get the 2nd door to open

Hint: doorOpen2 needs to move +5 studs to the right

Step 18
Next we'll learn to use Tweens to make the door open smoothly

Tweens are like inbetween frames between two events

We're going to add a bunch of motion frames inbetween the open and closed positions

Step 19
First import TweenService like this

Now we can use Tweens by referring to our tweenService variable

Step 20
Make a tweenInfo variable to set some tween options

Here I'm setting my tween to 1 second long, and the motion type to Linear

You may want to try different numbers of seconds

Step 21
Inside the openDoors function we'll create a new tween for each door

When we create a tween we supply:

  • Who: Which Object are we changing
  • How: How long and what easing style?
  • What: What property are we changing and to what value?
Step 22
Remove the old position changing code
Step 23
Instead we will simply be instructing each tween to Play
Check Your Work
Step 24
You should now have smoothly opening sliding doors!
Step 25
In the next lesson you will be constructing a Map for the player to play in
Roblox Heist: Sliding Doors Info


MVCode Clubs

Created By

Newprofile jamie


Roblox Heist Game

Access Level


For Teachers and Schools

Teach coding to your students with MVCode Teach

MVCode offers an integrated product designed to teach coding to students.

Learn more about MVCode Teach