Matchmaking system

So, the perfectly working code below (as of now), will send people to a private server. (There is more code that is unrelated, but changes the group properties)


local f = workspace:WaitForChild("Matchmaking")
local info = require(script.Settings)
local tp = game:GetService("TeleportService")

-- Function to create a private server and teleport players to it
local function createAndTeleportToPrivateServer(players,main,current)
	local host = game.Players:FindFirstChild(main)
	
	local reservedServerCode = tp:ReserveServer(14123061693)
	if not reservedServerCode then
		warn("Failed to reserve a private server.")
	end
	
	local success, errorMessage = tp:TeleportAsync(reservedServerCode, players)
	
	if success then
		print("Teleported players to the private server.")
	else
		warn("Failed to teleport players to the private server:", errorMessage)
	end
end

-- Define the "Group" class
local Group = {
    currentPlayers = 0,
    difficulty = "",
	gamemode = "",
	plrs = {},
	modifier = ""
}

-- Constructor for the "Group" class
function Group.new(players, difficulty, gamemode,modifier)
    local self = setmetatable({}, { __index = Group })

    -- Initialize properties
    self.currentPlayers = players or 0
    self.difficulty = difficulty or ""
	self.gamemode = gamemode or ""
	self.plrs = {}
	self.modifier = modifier
	
    return self
end

-- Methods for the "Group" class
function Group:addPlayer(name)
	self.currentPlayers = self.currentPlayers + 1
	table.insert(self.plrs, name)
end

function Group:removePlayer(name)
	self.currentPlayers = self.currentPlayers - 1
	local new = {}
	for i, v in pairs(self.plrs) do
		if v ~= name then
			table.insert(new,v)
		end
	end
	self.plrs = new
end

function Group:setDifficulty(difficulty)
    self.difficulty = difficulty
end

function Group:setGamemode(gamemode)
    self.gamemode = gamemode
end

function Group:setModifier(m)
	self.modifier = m
end

function Group:getPlayers()
    return self.currentPlayers
end

function Group:getDifficulty()
    return self.difficulty
end

function Group:getGamemode()
    return self.gamemode
end

function Group:getModifier()
	return self.modifier
end

function Group:getAll()
	return self.plrs
end

function Group:FindPlayer(name)
	for i, v in self.plrs do
		if v == name then 
			return false
		end
	end
	return true
end


I would like in this code, to be able to send the matchmaking data to the reserved server.

1 Like

You should read about TeleportAsync’s 3rd argument: TeleportService | Documentation - Roblox Creator Hub, which is TeleportOptions | Documentation - Roblox Creator Hub. With this, you can use SetTeleportData and GetTeleportData.

I did read about this, in teleport options it gave options for the id of a place and another for the jobid. There is no room in teleport options for your own data as far as I am aware.

That is only example data. You can send any object you want.

local teleportData = {
    placeId = game.PlaceId,
    jobId = game.JobId
}

teleportOptions:SetTeleportData(teleportData)

is only to show you what is possible.If you want, you can do

local teleportData = {
    server = 69,
    matchId = 120,
    gameMode = "FFA"
}

teleportOptions:SetTeleportData(teleportData)
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.