TeleportService Guide: Difference between revisions
>Crazypotato4 I added some links to the page |
>Ozzypig "speechmarks"? Really? Page made accurate. |
||
Line 6: | Line 6: | ||
=== 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 [[LocalPlayer|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 objects). | |||
== Creating the script == | == Creating the script == | ||
First of all we need to get the service by using the [[GetService|:GetService()]] method of [[DataModel| | First of all we need to get the service by using the [[GetService|:GetService()]] method of [[DataModel|`game`]]. | ||
<pre> | <pre> | ||
Line 23: | Line 20: | ||
</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 26: | ||
</pre> | </pre> | ||
Next, write the [[Teleport_%28Method%29|:Teleport()]] method of TeleportService. | |||
<pre> | <pre> | ||
Line 39: | Line 32: | ||
</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 38: | ||
</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 45: | ||
<pre>game:GetService("TeleportService"):Teleport(8473728, "SpawnLocation")</pre> | <pre>game:GetService("TeleportService"):Teleport(8473728, "SpawnLocation")</pre> | ||
Revision as of 21:14, 22 July 2011
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 objects).
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, write 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")