How to make a matchmaking System?

Hello. I was working on my project a few minutes ago then I thought I should teleport players to a reserved server on another place but when I tried, it keeps giving me an error so now I have NO IDEA how to make one any help? How do I make a matchmaking system that is private

Do you ask for certain ways of how you do that, or do you have a code issue that you need solved?

I had a code but it gives me the same error and I gave up so deleted that code now I need a new code

You could do something like this:

function establish_Teams()
	if not #game.Players:GetChildren() >= 2 then return nil, nil end; -- If the players in the game are less than 2
	local team1 = {}
	local team2 = {}
	local lastAdd = 1;
	for _, v in ipairs(game.Players:GetChildren()) do -- Looping through the players
		if v:IsA("Player") then -- If the current loop object is a player class object
			if lastAdd == 1 then -- If we already added last time to team1, then add to team2
				table.insert(team2, #team2 + 1, v) -- Inserting player into the table
			elseif lastAdd == 2 then
				table.insert(team1, #team2 + 1, v) -- Inserting player into the table
			end
		end
	end
	
	return team1, team2 -- Returning both teams
end;

function start_Match()
	local team1, team2 = establish_Teams(); -- Establishing teams.
	if team1 == nil or team2 == nil then return end; -- If players are less than 2, it returns nil, so re-checking what it returned.
	local teleportPlayers = {}; -- Creating a table, to be later used
	
	for _, v in ipairs(team1) do -- Looping through team 1
		table.insert(teleportPlayers, #teleportPlayers + 1, v); -- Inserting value into the table
	end;
	
	for _, v in ipairs(team2) do -- Looping thrugh team 2
		table.insert(teleportPlayers, #teleportPlayers + 1, v); -- Inserting value into the table
	end;
	
	local goalGame = 53131531 -- Defining a goal gameId
	local teleportService = game:GetService("TeleportService") -- Getting teleport service
	teleportService:TeleportPartyAsync(goalGame, teleportPlayers) -- Teleporting both teams into the game
end
1 Like

Does teleportpartyasync teleports them to a private server because I don’t want random people to join random servers

2 Likes

You can do something like this:

local Teams = game:GetService("Teams")
local Players = game:GetService("Players")

function startMatch()
   local playersInMatch = Teams["Playing"]:GetChildren()
   -- Do stuff here
end

while true do
   -- Do stuff here
   startMatch()
   wait(120)
end