TeleportService Guide: Difference between revisions
>SoulStealer9875 New page: == 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 ... |
m Added category |
||
(10 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
{{NonStandard|reason=The teleport service was added in 2011 and is not supported by most launchers and revivals.}} | |||
== Introduction == | == Introduction == | ||
TeleportService was created to teleport the local player from one place to another. | [[TeleportService]] was created to teleport the local player from one place to another. | ||
=== Why Should I use it? === | === Why Should I use it? === | ||
Line 6: | Line 7: | ||
=== How will this benefit me? === | === How will this benefit me? === | ||
It really does depend on how you use it. | 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 == | == 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 | The service runs off the [[LocalPlayer|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 [[Instance|instances]]). | |||
== Creating the script == | == Creating the script == | ||
First of all we need to get the service by using the :GetService() method of | First of all we need to get the service by using the [[GetService|:GetService()]] method of [[DataModel|`game`]]. | ||
<pre> | <pre> | ||
Line 23: | Line 21: | ||
</pre> | </pre> | ||
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. | |||
Next we need to | |||
<pre> | <pre> | ||
Line 31: | Line 27: | ||
</pre> | </pre> | ||
Next, use the [[Teleport_%28Method%29|:Teleport()]] method of TeleportService. | |||
<pre> | <pre> | ||
Line 39: | Line 33: | ||
</pre> | </pre> | ||
Inside the parenthesis we need to put the ID of the place we wish to teleport to; for example 1818 (Crossroads). | |||
Inside the | |||
<pre> | <pre> | ||
Line 47: | Line 39: | ||
</pre> | </pre> | ||
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 [[Beginner%27s_GUI_Tutorial|GUI]]) clone the LocalScript into one of the previously mentioned objects that will run LocalScripts. | |||
== Teleporting to a certain spawn == | == Teleporting to a certain spawn == | ||
Line 53: | 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
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")