Roblox Heist: Sliding Doors

Planning
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

Temp1532034907

You MUST name your doors and the button

Step 3
Add an empty Model to the Workspace
Temp1532034960

Name this model something like Front Doors

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

Like this

Temp1532035467
Planning
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
Temp1532036011

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

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

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"
Temp1532036297
Step 9
Create references to the button, the doors, and the clickDetector
Temp1532036795

We can find the doors by using button.Parent

(which is the Front Doors Model):

Temp1532036417
Step 10
Create a function named "openDoors" and connect it to the MouseClick event of clickDetector
Temp1532036994
Step 11
For now, have this function simply print to the output window
Temp1532037042
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)

Temp1532039575

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
Temp1532039943
Check Your Work
Step 16
Now the door should open correctly

...and I'm freee!

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

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

Planning
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
Temp1532041134

Now we can use Tweens by referring to our tweenService variable

Step 20
Make a tweenInfo variable to set some tween options
Temp1532041359

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
Temp1532041573

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
Temp1532041723
Step 23
Instead we will simply be instructing each tween to Play
Temp1532041782
Check Your Work
Step 24
You should now have smoothly opening sliding doors!
Planning
Step 25
In the next lesson you will be constructing a Map for the player to play in
Temp1532056189
Roblox Heist: Sliding Doors Info

Account

MVCode Clubs

Created By

Newprofile jamie

Course:

Roblox Heist Game

Access Level

premium

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