Teleporting a player to a place, but only to an existing server, not making a new server

Before I explain what I need help with, here is the context:
I have a universe/game/experience with two places. One place is the start place which you go to when you join the game. The second place is a place that you’ll be eventually teleported to from the start place.

What I need help with:
I would like to send the player to a server in place 2, but not make a new server. I want to send the place only to an existing server. If there aren’t any existing servers, then one gets made. If all existing servers are full, then nothing happens and the player doesn’t get teleported.

I don’t know how to approach this and need help coming up with a way to do it. I know about reserved servers but idk how I could use them for this.

The goal:
If people are playing place 2, then place 2 will always have 1 server, no more will get made.

1 Like

Change the place setting to fill the servers instead of optimize or whatever the default is and then you can just teleport them to the place

otherwise you could use Master Server // Cross Server MSS - Resources / Community Resources - DevForum | Roblox
to get a list of the servers and choose one to teleport to


I already have that, but when the first place gets filled up, a new server gets made. I don’t want it to be able to make a second server.

This could help me, thanks. I’ll try this

Yeah, if the memory store is shared across your two places then you can use the Server list to check if a server with the PlaceId of your second place already exists and prevent teleporting if its full, or if it there is still space in the one server you can teleport them there

you may need to modify the server ‘object’ to contain PlaceId

local function RegisterSelf()
	local ServerObj = {
		["JobId"] = game.JobId,
		["PlaceId"] = game.PlaceId, -- <-- Added PlaceId here
		["Players"] = GetPlayers(),
		["Runtime"] = math.round(time()),
		["FPS"] = math.round(AvgServerFPS),
		["Master"] = IS_MASTER,
	ServerIndex:SetAsync(game.JobId, HttpService:JSONEncode(ServerObj), 60)
	DebugPrint("Registered self as: "..HttpService:JSONEncode(ServerObj))
1 Like

You can use the list of servers in the loop while loop near the end of the script and modify it like this:

		local Place2Exists = false
		for JobId, Server in pairs(GetServers()) do
			DebugPrint("JobId: "..Server.JobId..", Players: "..#Server.Players..", Master: "..(Server.Master and "Y" or "N"))
			if Server.PlaceId == Place2PlaceId then
			    if Place2Exists then Server.Shutdown() continue end -- Shutdown second server
			    if #Server.Players < MaxPlayers then
			        Place2Exists = true
			if not Master and Server.Master then Master = Server end

but for your case you would want to loop the server list whenever you want to teleport a player, not in the main loop, so it would make sense to extract the server list from the main script into a different script using a BindableFunction ( (just return the Servers variable)

then it would look something like:

local BindableFunc = script.BindFunc

local Servers = BindableFunc:Invoke()
local Place2Exists = false
for i = 1, #Servers do
    local Server = Servers[i]
    if Server.PlaceId == Place2PlaceId then
        if Place2Exists then Server.Shutdown("Only one server is allowed") continue end
        Place2Exists = true
        -- Teleport to Server.JobId
if not Place2Exists then
    -- Teleport to PlaceId
1 Like