Using MessagingService to send info to specific server

Hello, I want to do what the title says.
So, I make a reserve server and I have the code for it, is there a way I can use this reserve server code to send info to it with MessagingService?

1 Like

maybe this can help you

Assuming your trying to make a match-making system

You need to do the following to achieve it:

When your having a queue in different servers, name it using a UUID
You can get a UUID like 1u23012-239329329-292

Now get a queue like this:

local tableofqueues = {
  ["129191-29292-29292"] = {
        ["game-mode"] = "basic",
        ["players"] = {} -- an array of players userid not name
   }
}

Like you said, use messaging service to send a message to all servers
Now do this:
When you get the uuid of the queue server, check if the server have the uuid, if yes, teleport all the players of the queue in the server, to the reserve id

However, a player might not be present during the teleport process, so make sure to check the player if they exist and wrap it in a pcall

You can just send a message with the code in the data, and then in a SubscribeAsync function, check if the sent code is the same as that servers code.

MessagingService:PublishAsync("example", {Code = your_code_here})

In the other place:

local code = the_code_here -- assuming that you are already sending the code here

MessagingService:SubscribeAsync("example", function(msg)
   if msg.Data.Code == code then
      -- this message is meant for only this server!
   end
end)

OR, just publish and recieve messages with the code as the topic.

1 Like

this doesn’t answer the question, as it still sends the message to all servers.

you have to dynamically generate the topic name with the jobId concatenated to it such as:

local topicName = “myTopic:” … game.JobId

and keep a cache of active servers in MemoryStore so you can refer to their jobIds later. you can store additional data and flags in this cache based on your individual needs. this could get convoluted but it’s the only way to do exactly what OP is asking.