How can I pick two random people in different servers?

Lets say there is two servers,
Server A has 5 players. ROBLOX, badcc, Minitoon, Coeptus, Callmehbob.
Server B has another 5 players. Clonetroop1019, mrflimflam, NowDoTheHarlemShake, SamsonXVI, Amanda, and Coefficients

(Yes I had a hard time thinking of 10 popular roblox figures, these are all I could think of)

How can I use messaging service to pick two random players from different servers, say, Amanda and Coeptus?

There is an service allow you cross-server commination. It’s messaging service

Perhaps this article might be helpful for you.

Yes I know what that is, i just need a way to tackle the task at hand. I want to create a matchmaking system with this, and I was thinking about firing a server event from the client, if it was fired, publishasync, with the player’s name, somehow check anyone from the server also had this event fired, match them together, and teleport? Is this a good way to do this task, or should I handle it differently?

If you are beginner at MessagingService then I recommended start off with simple task such as sending message to another server and print it. Once you done this, slowly increase difficult and get better. Try to start off with simple, I am sure you will become better.

If you disagree above the message then here what you should do :

Bit complex way : 
  1. Send random player name using publish async
  2. Add the player name into table
  3. Loop the table and print player name 

Simple way  :  (inspired from someone...)
  1. Add all players in to the table (yes, all players in all server)
  2. Use math.random to select random player name in the table

EDIT : Please note. I expect you have basic knowledge of scripting and knowing how to optimize thing such as reducing lag, script line, parts in workspace, etc…

Add all the players to a big table using messaging Service, pick 2 random people from it

1 Like

That’s the simple way to do it

1 Like

I love how u added it to ur reply lol

1 Like

Tried this, got an error:

Here is the script, help?

local AoQ = game.ReplicatedStorage.AddtoQueue
local RFQ = game.ReplicatedStorage.RemoveFromQueue
local MessageService = game:GetService("MessagingService")
local TeleportService = game:GetService("TeleportService")
local PlayersToMatch = {}
local place = 10262480669
AoQ.OnServerEvent:Connect(function(player)
	table.insert(PlayersToMatch, player)
	MessageService:PublishAsync("ChosenPlayer", PlayersToMatch[math.random(#PlayersToMatch)])
end)
RFQ.OnServerEvent:Connect(function(player)
	table.remove(PlayersToMatch, player)
end)
MessageService:SubscribeAsync("ChosenPlayer", function(player)
	TeleportService:TeleportPartyAsync(place, {player.Data, PlayersToMatch[math.random(#PlayersToMatch)]})
end)

The error of the message say. Cannot publish ‘Instance’. Can only Publish ‘string’.

yeah i know but i do need to publish it to send it to the place, how can i work around it?

You mean send it to another game?

it is a problem?? i want to know how to FIX it

yes, publish the player and send to another game

I don’t think you can send it to another game. I will try to find a way to do it

ok, wb the actual error, how can i fix it?

Send player name. Not instance

Master Server // Cross Server MSS - Resources / Community Resources - DevForum | Roblox

for JobId, Server in pairs(Servers) do
    DebugPrint("JobId: "..Server.JobId..", Players: "..#Server.Players..", Master: "..(Server.Master and "Y" or "N"))
    -- Can access players with 'Server.Players'
end
  • The server ‘obj’ contains .Players, .IsLocal, .Send(), .Shutdown(), .JobId, .FPS, .Master and .Runtime
  • The player ‘obj’ contains .Age, .UserId, .Name, .Ping and .Connection
while true do
	local ServersTable = {}
	for _, Server in pairs(Servers) do
		table.insert(ServersTable, Server)
	end
    if (#ServersTable < 2) wait(10) continue end
	local AllPlayersDict = {}
	for _, Server in pairs(ServersTable) do
		for __, Player in pairs(Server.Players) do
			AllPlayersDict[Player.UserId] = Player
		end
	end
	local AllPlayersTable = {}
	for _, Player in pairs(AllPlayersDict) do
		table.insert(AllPlayersTable, Player)
	end
    if (#AllPlayersTable) < 2 then wait(10) continue end
	
	local RandomIndex = math.random(1, #AllPlayersTable)
    local RandomPlayer1 = AllPlayersTable[RandomIndex1]
	table.remove(AllPlayersTable, RandomIndex)
	RandomIndex = math.random(1, #AllPlayersTable)
    local RandomPlayer2 = AllPlayersTable[RandomIndex1]
	table.remove(AllPlayersTable, RandomIndex)
    print(RandomPlayer1.Name.." (Ping: "..RandomPlayer1.Ping.." UserId: "..RandomPlayer1.UserId..")")
    print(RandomPlayer2.Name.." (Ping: "..RandomPlayer2.Ping.." UserId: "..RandomPlayer2.UserId..")")
    break
end

I tostringed it, and now it says Attempt to concatenate string with Instance

local AoQ = game.ReplicatedStorage.AddtoQueue
local RFQ = game.ReplicatedStorage.RemoveFromQueue
local MessageService = game:GetService("MessagingService")
local TeleportService = game:GetService("TeleportService")
local PlayersToMatch = {}
local place = 10262480669
AoQ.OnServerEvent:Connect(function(player)
	table.insert(PlayersToMatch, player)
	MessageService:PublishAsync("ChosenPlayer", tostring(PlayersToMatch[math.random(#PlayersToMatch)]))
end)
RFQ.OnServerEvent:Connect(function(player)
	table.remove(PlayersToMatch, player)
end)
MessageService:SubscribeAsync("ChosenPlayer", function(player)
	print("We have chosen"..player.Data.." vs. "..PlayersToMatch[math.random(#PlayersToMatch)])
end)
SERVICE:PublishAsync(player.Name)

player.Name is going to be the name of the local player tho