TeleportToSpawnByNameFunction of TeleportService
void TeleportToSpawnByName ( int64 placeId, string spawnName, Player player = nil, Variant teleportData, ScreenGui customLoadingScreen = nil )Parameters:
Description: Teleports someone like Teleport, but has a second argument allowing someone to teleport to a certain spawn. However, the spawn must have its Neutral property set to true. The given teleportData can be any value that can be stored in a datastore, and will be transported along with the player. The customLoadingScreen is a GUI that'll be made static (scripts don't run, TweenPosition etc doesn't work, ...) and displayed during teleporting. You can see these arguments after the player has been teleported, using LocalPlayerArrivedFromTeleport.
This code will teleport a player to Crossroads, and if there is a spawn named "TeleportSpawn" then the player would spawn on it. This assumes it's being used in a LocalScript.
The below does the same as the code shown above, but from a Script. It assumes that there's a Player named 'Telamon'.
game:GetService('TeleportService'):TeleportToSpawnByName(1818, "TeleportSpawn", game.Players.Telamon)
Tutorials Used In