Reserve Server "Names"

I’m making a game consisting of different servers.
I want to utilise ReserveServer/Teleport

Is it even possible to set a “name” for a ReservedServer and teleport someone to a specific one? If not, can somebody suggest an alternative? Cheers.

Nope, server dont have names.
They have id.

and if you actually want the server names then you can use DataStores, then generate a random server name or get the player to choose it.
Then update the name to the server.

I’ll give you an example:

local dataStoreService = game:GetService("DataStoreService")
local data = dataStoreService:GetDataStore("Servers")

local serverInfo = {
    Name = "Test #1",
    Code = "" -- The code you get from TeleportService:ReserveServer
    ActivePlayers = #game.Players:GetPlayers()
}

local currentServers = data:GetAsync("list") -- gets all the servers table
if currentServers then -- if theres data then
  table.insert(currentServers, serverInfo) -- It will insert this server in the server table
  -- Using :UpdateAsync in this one bc its good for tables (it will update if data exists)
  data:UpdateAsync('list',function(oldData) -- It returns old value too! 
         return currentServers -- Returning the current server table so value can update.
  end)
else -- If theres no data then
  currentServers  = {} -- Makes an empty table
  table.insert(currentServers, serverInfo) -- Adds server info to the empty table

 -- Saving the data (using :SetAsync because theres no data)
  data:SetAsync('list', currentServers)
end

When you get the data by using

data:GetAsync('list')

The expected output will be:

{
   [1] = {
        Name = "Test #1",
        Code = ""     
    }
}

The number is the index, theres only one server we’ve added so it will show one.
When you add more servers it will add into the table

{
   [1] = {
        Name = "Test #1",
        Code = ""     
    },
    [2] = {
        Name = "My awesome server!",
        Code = ""     
    },
    [3] = {
        Name = "Another server!",
        Code = ""     
    }
}

Note: Make sure to do the saving part (Active players, server name) from the private server (the server you got from TeleportService:ReserveServer()) and the code part from the main game.

3 Likes