How would I teleport a player to their desired map in a seperate place?

So I’m making a multiplayer game with different maps and modes and I have 2 places: The menu (Start place) and the main game which stores all the maps. I’m trying to make a system where if a player clicks a map, it will teleport them to a server in the main game with that map. I have an idea which utilizes teleport data, but that’s only for servers that have just been created. How would I achieve this?

1 Like

Well you have 2 options.

Option1.
If each map is in a different place then just have a dictionary that stores the map names as the key and the placeId as the value:

local places {
    ["Frozen"] = 111111,
    ["Inferno"] = 222222
}

Then choose the map you want and get placeId places[mapName]
Then use TeleportService to teleport the player to that place.

Option 2
If all maps are in the same place, use TeleportService’s TeleportData and send the map name and then in the place with the maps get the map name in a local script local mapName =TeleportService:GetLocalPlayerTeleportData()
And then finally send a remote event (pass the mapName as a parameter) and create the map.

Also use DataStoreService to send the mapName instead of TeleportData so exploiters can’t change the values

Some resources for you:
https://developer.roblox.com/en-us/api-reference/class/TeleportService
https://developer.roblox.com/en-us/api-reference/function/TeleportService/GetLocalPlayerTeleportData
https://developer.roblox.com/en-us/api-reference/class/DataStoreService

3 Likes

Thanks, is there anyway to teleport a player to an already existing server in the main place with their desired map?

1 Like

I don’t think so. Chars

1 Like

Would teleporting the player over and over again until it finds a server work?

1 Like

Or I could make separate places and use a service to insert the code and weapons into the place, but then I don’t know how to make the gamemode stuff.

1 Like

Look, what I would do is my option 1.

Directions to get started

  • Navigate to the view tab in studios
  • Click on Asset Manager and then double click where it says Places
  • From there right click on the menu and click Add new place

Doing that should open up a new baseplate. This baseplate is a new place under your roblox “experience”. Now in this place what you should do is make all the code for 1 map. Then, go back to your new place and do the following:

  • Rename the place in the Asset Manager to the name of the map (for organization)
  • Right click on that place and click Copy ID To Clipboard

Then follow the steps from my other reply:

Make sure you add each map to the table as well as their unique ID

I’ve been messing with this myself. I have found that you have a few options.

If you are sending data between the starting place and the actual place where the game itself has multiple maps, then you can use MessagingService to send data along with the player to do that. You would need to include the player’s UserId so the code at the target place knows which data goes with which player.

To send a player to an already running place, you would first capture the player.UserId of the first player then teleport them using TeleportService:TeleportAsync(). After that you would use TeleportService:GetPlayerPlaceInstanceAsync() to get the game.JobId then use TeleportService:TeleportAsync() or TeleportService:TeleportPartyAsync() if you’re teleporting more than one player at a time. To specify the JobId, you use TeleportOptions. There is an option to specify the JobId of the teleport target instance.

There is also a TeleportAsyncResult that has a few things in it as well. Roblox also has some example code as well which can be found here: Teleporting Between Places.

One thing that I would like to mention is that when the first player arrives, you can use the MessagingService to send an alert back to the starting place. In the received message event handler, you would task.wait(1) or so then call GetPlayerPlaceInstanceAsync to get the JobId. That would guarantee that the player is there when you call that method.

I’m still working on this myself. The main limitation that I’m running into is that the teleport options are documented as not working in Studio, which is a pain. You have to test it on the live server, which makes debugging nearly impossible.

The JobId is a 128-bit GUID/UUID/CLASSID in the form of xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx where ‘x’ is a hexadecimal digit (0-9, a-f).

1 Like

Thanks, I’m a bit new to teleportservice and messagingservice, how would I do this?

Follow the example code that Roblox provides at the guides and links that I posted. I’m still kind of new to it myself, but I am working on a system to pull this off. Right now, I have built something like a IP stack on top of the messaging service because it says that delivery is “best effort” since it must be fully reliable for my needs. I might revisit it and take some of the complexity out of it. Something like keep sending the message until the sender receives an acknowledgement.

To use the messaging server, you need to create a ‘channel’ (I think they called it a messaging group or something) using the provided methods. I would pick something unique, like the game ID or something. Then you can send tables across using game.JobId’s as the source and destination addresses. As for the teleport, follow the guide. That’s what I’m doing. Remember, I’m still working on this myself, so I don’t have all the answers.

1 Like

Do you know how I would create a server with no players?

1 Like

To my knowledge, you can’t. If there are no players in a server, the hypervisor spins down that server instance to conserve resources. When you start up a game for the first time, it takes a second for the hypervisor of the physical server to load the virtual machine from mass storage and into active memory. That’s why there’s a delay when entering an experience for the first time.