TeleportService Guide: Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
Added template
m Added category
 
Line 46: Line 46:


<pre>game:GetService("TeleportService"):Teleport(8473728, "SpawnLocation")</pre>
<pre>game:GetService("TeleportService"):Teleport(8473728, "SpawnLocation")</pre>
[[Category:Scripting Tutorials]]

Latest revision as of 03:02, 17 May 2024

Ouch!
The following article, TeleportService Guide, mentions a feature exclusive to certain versions of the client.
Specifically: The teleport service was added in 2011 and is not supported by most launchers and revivals.


Introduction

TeleportService was created to teleport the local player from one place to another.

Why Should I use it?

You can use it as a way of advertising someone else's place, or your own place as a GUI. So you can click the button and it will teleport you to the place.

How will this benefit me?

It really does depend on how you use it. If you do not want to teleport players away from your place, then you shouldn't use this. However, if you have multiple places you could make one place that takes the player to many different places.

How to use it

The service runs off the local player, meaning you can't run it off a normal script inside a regular area such as workspace.

So you will need to insert a LocalScript into a player's Backpack, PlayerGui, or Character (LocalScripts will only run in those instances).

Creating the script

First of all we need to get the service by using the :GetService() method of `game`.

game:GetService()

Next we need to give the name of the service as a parameter, which is TeleportService. Since the name is a string, we need to put quotation marks around it.

game:GetService("TeleportService")

Next, use the :Teleport() method of TeleportService.

game:GetService("TeleportService"):Teleport()

Inside the parenthesis we need to put the ID of the place we wish to teleport to; for example 1818 (Crossroads).

game:GetService("TeleportService"):Teleport(8473728)

This is all the scripting you need for teleportation. To actually teleport someone, you need to have another script (such as a button script for a brick or GUI) clone the LocalScript into one of the previously mentioned objects that will run LocalScripts.

Teleporting to a certain spawn

With this service you can teleport to a certain spawn, all you need to do is put the spawn's name as the second argument.


game:GetService("TeleportService"):Teleport(8473728, "SpawnLocation")