Cross-Server Teleporting

Hello,

I am currently trying to make a global matchmaking system, and it’s been going fairly smoothly so far, until I got to the teleporting bit. Once enough players are found in the queue, the game will teleport each of them into the same place so they can play together, although I do not know how to accomplish this.

I’ve tried using MessagingService to publish a table globally, that includes the players in the queue, and a private server access code, which has failed to work. Since the access code is generated differently across each player’s device, the code will be different for each player in the queue, which therefore teleports each of them to separate reserved servers.

SubscribeAsync code bit:

local Topic = "GlobalQueue"

MessagingService:SubscribeAsync(Topic, function(Info)
	local Data = Info.Data
	local PlayersInQueue = Data.PlayersInQueue
	
	for i, p in pairs(Players:GetPlayers()) do
		if table.find(PlayersInQueue, p.Name) then
			TeleportService:TeleportToPrivateServer(PlaceID, Data.AccessCode, {p})
		end
	end
end)

PublishAsync code bit:

local PlrsInQueue = {}

for _, d in pairs(msg) do
	local ID = d.value
	local Username = Players:GetPlayerByUserId(UserId).Name

	table.insert(PlrsInQueue, Username)
end

task.delay(3, function()
	MessagingService:PublishAsync("GlobalQueue", {
		PlayersInQueue = PlrsInQueue;
		AccessCode = TeleportService:ReserveServer(PlaceID)
	})
end)

I do not know if I’m going about this problem the wrong way, so any help is appreciated, thank you.