Custom matchmaking with server code

  1. What do you want to achieve?
    so i was making a custom matchmaking system , and also the code to join specific server
    .(it’s like a player join a private server , and other player can join that server by typing the
    correct code)
  2. What is the issue?
    i don’t know how can i make that , i think it needs something call reserve server , but i
    don’t know how to use it , so can somebody give me an example ?
1 Like

ReserveServer has a code sample if you were unsure of how to use it specifically. I strongly recommend doing research on the Developer Hub first and then making an attempt at solving your problem if you don’t know before posting a thread. Helps to lay a foundation at least.

but i dont know how it work , like how is the code looks like , and how do i make it in a textbox ? pls give a example script .

There is a code sample on the page so you can see how the code looks like. ReserveServer, when called with a PlaceId, will give you back two variables: an access code needed to join a private server using TeleportToPrivateServer and the server’s unique id. You will need a RemoteEvent if you intend to have a client input the code in a text box.

I don’t mind giving you pseudocode, not a full script though, but you should try and do this on your own first given that you’ve been linked directly to the documentation page. The Developer Hub is a good place to start doing research and making an attempt first. Once you’ve tried, you can ask for help regarding the things you’ve already tried.

-- Create a reserved server of the current place and send its id to the console
-- so it can be copied out. Ignore second variable since we don't need it.
local code = TeleportService:ReserveServer(game.PlaceId)
print(code)

-- Additionally also listen when the client fires the remote. Additional security
-- checks, if needed, should be done on your own here.
RemoteEvent.OnServerEvent
    TeleportService:TeleportToPrivateServer(your_arguments_here)

-- Have the client enter the code in a TextBox.
TextBox.FocusLost
    RemoteEvent:FireServer(TextBox.Text)
1 Like

is this correct ?

Local Script - Creating Reserve Server

local TextBox = script.Parent 
local Button = script.Parent.Parent.Button
local plr = game.Players.LocalPlayer

local RemoteEvent = game.ReplicatedStorage.RemoteEvent 

Button.MouseButton1Click:Connect(function()
   
   local Code = TextBox.Text
   RemoteEvent:FireServer(plr, Code)

end)

Server Script

local RemoteEvent = game.ReplicatedStorage.RemoteEvent 
local TeleportService = game:GetService("TeleportService")
local GeneratedCode = TeleportService:ReserveServer(game.PlaceId)

RemoteEvent.OnServerEvent:Connect(function(player, plr, Code)

     TeleportService:TeleportToPrivateServer(Game.PlaceId, Code, plr)

end)

i have a question , if somebody type the code that is not available , then they will create new reserve server ? and if the code was correct , they will be tp to the reserve server they want?

On line 3 in server script , the server will return a code when somebody created a new reserve server?

And last one , i saw that the Developer Hub used datastore , why?

Roughly. Just some things:

  • The client who fires a remote is implicitly sent as an argument. You do not need to pass the LocalPlayer as an argument to FireServer. You can use the player passed in OnServerEvent to perform teleport operations on.

  • TeleportToPrivateServer takes a table of players, check the documentation.

  • If a player types a code that doesn’t exist, they won’t get sent to a private server. You should build this into your workflow; reserving servers should be done by players creating a match and entering codes should be done by players joining one.

New reserved servers are not created if someone types a code that doesn’t exist, that’d be again something you need to build into your own flows.

The second example uses DataStores to show an example of a reserved server that’s saved that can later be joined by using a chat command.

but if i didnt make the local player , im pretty sure the server will teleport all of the players in that server , which i dont want .

So the reserve server function is actually create a new server but you actually haven’t tp to there yet , it’s just code generated for the server . you still need to type the code to join to that reserve server? (correct me if i’m wrong)

Also , i realise there is no place id for the server you want to teleport , should i replace the Place ID to the server id the player gonna tp?

Why would it teleport everyone? You’re only teleporting the client who fired the remote.

Remote.OnServerEvent(player) --> the person who fired the remote
    TeleportToPrivateServer(..., {player}) -- teleport only this client

I do strongly recommend research at this point so it’s a little easier to understand what you’re writing first. If you don’t have the foundational knowledge regarding the instances you’re working with, then it’ll be difficult likewise to make a full system involving them.

1 Like

ohhhh , i understand now . Thanks for the info !