In this video,
I'll show you how to make a teleporter pad
in Roblox Studio.
Teleporter pads allow players
to quickly move around the game.
You can set up two pads so that when you step on pad one,
you instantly teleport to pad two and vice versa.
Firstly, inside the Roblox Studio,
click on the home tab and insert two parts.
Name the parts Pad1 and Pad2.
Then select both parts in the explorer,
set their size to 4 by 1 by 4,
and set the color of each pad
so that we can tell the difference between them.
I'm going to drag the teleporter pads away from each other
so that we can notice the teleporting.
Next, insert a script into Pad1.
In this script, let's create a variable
to hold the path to the other pad,
which we will be teleported to.
Write "local Pad
= game.Workspace.Pad2."
We now have a reference to the other pad.
Next, let's create a touched event,
which will fire and execute code
when the user touches our pad.
Write "script.Parent.Touched
:Connect,"
and then we'll have an opening bracket.
Inside of there,
we'll put "function"
and we'll have another pair of brackets.
And then we'll drop a line,
and make sure that you've got an "end"
with a closing bracket.
Now, inside our second pair of brackets,
let's insert an argument called "hit."
The "hit" inside of the bracket, our argument,
will be the object which touches our teleporter pad.
This will likely be one of our player's body parts.
We'll need to check this
to make sure only players get teleported,
since other blocks can touch our teleporter as well.
Let's create a variable
to store the result of a function call
to check if this object's parent
is indeed a player character,
since body parts are stored within a character model.
Write "local Player
= game.Players:GetPlayerFromCharacter"
and in bracket write "hit.Parent."
Now, this variable will either be true or false,
and it tells us whether there is
an actual player touching our brick.
Next, let's write a simple if statement to check this.
Write "if Player then."
Drop a line.
Make sure you've got an "end."
Inside of this if statement,
let's check to make sure they're not currently teleporting.
We need to do this to prevent the player
from being teleported back and forth constantly.
Before we do that, let's create a value
which we can store in the player's character
to hold a true or false value
on whether the player is currently teleporting on a pad.
Click on the arrow next to StarterPlayer
in the explorer panel to expand this service.
Then, inside StarterCharacterScripts,
click on the plus icon
or right-click and select insert object.
Search for a bool value and select it.
Then select the bool value,
and in the properties window,
which you can access by pressing "VIEW" in the ribbon menu,
edit the name property to "CurrentlyTeleporting."
Back in our script,
let's create a variable for this value,
which we just created,
so we can keep a reference to it.
Write "local CurrentlyTeleporting
= Player.Character
: FindFirstChild ("CurrentlyTeleporting")."
Since the currently teleporting value
might not be in our player for some reason,
we can do a quick check to ensure the script
only continues if the value is present.
Write "if not CurrentlyTeleporting
then return end."
Now let's check the value of our currently teleporting
bool value by writing
"if not CurrentlyTeleporting.Value then,"
drop a line, and "end."
Now inside this second if statement,
let's set the currently teleporting value
to true for three seconds
so that the player can't teleport back to the origin pad
until the cool-down is over.
Write "CurrentlyTeleporting.Value = true."
Let's write a line of code to teleport the player
to the pad we referenced at the start of the script.
Write "Player.Character.HumanoidRootPart
.CFrame = Pad.CFrame
+ Vector3.new,"
and in brackets write "0,5,0."
Drop a line and write "wait."
And then in brackets write "3."
Then after the cool-down for three seconds,
let's set the currently teleporting value back to false.
Write "CurrentlyTeleporting.Value = false."
Now let's test our first pad to make sure it works.
I'm going to close our script,
and then I'll click on the home tab
and select "Play solo."
Then walk over to Pad1.
You should be teleported to Pad2.
If the pad doesn't work,
check the output window by clicking on the view tab
and selecting "Output."
This should log any error messages from your code
if there are any.
Since we've so far only coded one pad,
make sure that you're walking over the right one.
Next, let's script our second pad
to send users back to the original one.
I'm going to copy the script from Pad1 by selecting it,
right-clicking, and choosing "Copy."
Then I'm going to select Pad2 in the explorer window,
right-click on it, and choose "Paste into."
Then in the Pad2 script,
I'm going to change the pad variable
to instead reference Pad1.
Now, I'm going to test the game again,
and as you can see,
both my teleporter pads are now working.