How use MessagingService

Hi, i was looking tho the roblox services and i found MessagingService. I thought it was a messaging to a player service but actually is a server-going message.
i made a example script:

local MessagingService = game:GetService("MessagingService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Admins = require(script.Parent.SettingsAdmin).Ranks -- Getting the IDS for admins

function IsAdmin(player)
	for _, v in pairs(Admins) do
		if Admins == player then
			return true
		end
	end
	
	return false
end

game.Players.PlayerAdded:Connect(function(plr)
	if IsAdmin(plr.UserId) == true then
		local gui = game:GetService("ServerStorage").GUIS.AdminGUI:Clone()
		gui.Parent = plr.PlayerGui
		plr.PlayerGui.ChildAdded:Connect(function(child)
			if child:IsA("ScreenGui") and child.Name == script.AdminGUI.Name and IsAdmin(plr) == false then
				plr:Kick("Reason: \n Exploiting to AdminScreen. \n Kicked By System")
			end
		end)
	end
end)

ReplicatedStorage.Remotes.MessageEvent.OnServerEvent:Connect(function(plr, message)
	MessagingService:PublishAsync("Global Message", message)
	print(message.Data)
end)

MessagingService:SubscribeAsync("Global Message", function()
	-- Empty
end)

I dont know what to put in MessagingService:SubscribeAsync’s Function
if you know, please tell in the comments

https://developer.roblox.com/en-us/api-reference/function/MessagingService/SubscribeAsync

Something like

MessagingService:SubscribeAsync("Global Message", function(data, t)
	print("Got a message on the Global Message channel, with data " .. tostring(data) .. " which was sent at  time " .. tostring(t))
end)
1 Like

Thanks! but also… isnt messagingService crossServer?
like a remote was fired with a gui with the message and it will show to all servers of the game.

It is cross-server, but I believe the server that published the message will also receive it with SubscribeAsync, but not sure.