Teleporting player(s) to a reserved/private server?

I’m allowing players to make a private server that friends/other players can join if they would like although I’m unsure how to achieve this.

I got the player in the private server, the problem is letting the other players join them. I need to get the privateServerId which from what I can see can only be retrieved by :ReserveServer() and not GetPlayerPlaceInstanceAsync() which I thought what was I need to use. Is there another way to teleport players to a private server via jobId? Or is there another way I can get the privateServerId to teleport the players.

Here is my code:

if art == "getServerData" then --// returning the data of the server they want to join
	return {game["Teleport Service"]:GetPlayerPlaceInstanceAsync(args[1])} -- returns place and jobId, i need privateServerId..??
	
elseif art == "tpToInstace" then --// teleporting the player to the desired server
	game["Teleport Service"]:TeleportToPrivateServer(args[1], args[2], player)
	
elseif art == "tpToPrivate" then --// teleporting player to a new private server
	local code = game["Teleport Service"]:ReserveServer(game.PlaceId) -- returns the privateServerId
	local options = Instance.new("TeleportOptions")
	options.ShouldReserveServer = true
	
	game["Teleport Service"]:TeleportAsync(game.PlaceId, {player}, options)
	return true
end

Yes ReserveServer returns the code but not every player will be in the same server so I cant store the code there, and the last thing I want to do is create a datastore.

1 Like

Firstly, you are using TeleportAsync the wrong way.
The code for the reserved server is retrievable from the TeleportAsyncResult which is returned by TeleportAsync. You can remove the line with :ReserveServer().

Unfortunately, there are not many other possibilities. How should players from other servers know the code?

Leaving in the ReserveServer was a mistake, not intentional. I share the code via a data store and the player can still not join. It tries to send the player to the server but gets stuck in a loop, I try again and I get an error about the previous Teleport request is still processing.