Send Message to messaging service

Hello, I need a help on sending messages to messaging service, I am making a soft shutdown for all server and I wan’t them to see the reason of the shutdown

I am using a local script firing an event and when the event is fired the messaging service is called, now I did all that and it worked, but how could I send the reason of the shutdown to the messaging service

this is the code I use(not sure if you need it) to soft shutdown the whole server

local Sucess,Err = pcall(Api.SubscribeAsync,Api,"Restarting Server",function(Caller)
	
end)

Hope you could help me, Thank you

1 Like

Roblox Cross Server Messaging Docs

When using MessagingService:PublishAsync(MESSAGING_TOPIC, shared_message)
You can pass arguments in the shared_message tag. You can pass strings, numbers, bolean, or even tables.

So for exemple, If I create the following table

var mySharedMessageTable = {
 name = "chicken",
 isSomething = true
}

and then send it using MessagingService:PublishAsync(MESSAGING_TOPIC, mySharedMessageTable ) all servers listening to the MESSAGING_TOPIC will get fired. Now that they are fired, you need to get the table.

Here a exemple of a listening server (based on the roblox docs) :

local MessagingService = game:GetService("MessagingService")

local Players = game:GetService("Players")


local MESSAGING_TOPIC = "MySuperCoolMessagingTopic"

	local subscribeSuccess, subscribeConnection = pcall(function() -- Using pcall to catch errors, recommended practice.

		return MessagingService:SubscribeAsync(MESSAGING_TOPIC, function(message) -- here we set a listener to the `MESSAGING_TOPIC` and we set the variable `message` that will contain the shared table 

			print(message.Data) -- Here, the table is under message.Data, your shared vars will always be under message.Data even if it isn't a table. This will print the whole table.
              print(message.Data.name) -- will print "chicken"

		end)

	end)

There might be errors since Ive made this exemple fast, I recommend you to check the first link to get a better undestanding.

1 Like

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