Codectionary / Developer documentation / Luau

MessagingService

Publish a small notification to live servers in the same experience.

Why use MessagingService?

MessagingService supports cross-server publish/subscribe communication. Delivery is best effort and not guaranteed, so it is suitable for transient notices rather than durable purchases or saved player progress.

Try it in Roblox Studio

Put this Script in ServerScriptService in a published experience. Test with separate live servers when possible; one local Studio session may not reproduce cross-server behavior.

Syntax

MessagingService:SubscribeAsync(topic, callback)
MessagingService:PublishAsync(topic, message)

Examples

MessagingService

Subscribe to a short topic and publish a test notice.

local MessagingService = game:GetService("MessagingService")
local topic = "PracticeNotice"
local subscribed = pcall(function()
    MessagingService:SubscribeAsync(topic, function(message)
        print("Notice:", message.Data)
    end)
end)
if subscribed then
    local published = pcall(function()
        MessagingService:PublishAsync(topic, "Hello servers")
    end)
    if not published then
        warn("Notice could not be published")
    end
else
    warn("Notice subscription unavailable")
end
  1. SubscribeAsync registers a callback for messages on the named topic; the callback reads message.Data.
  2. PublishAsync sends the short string to subscribers, subject to service limits.
  3. Both calls can fail, and even a successful publish does not guarantee delivery. The example reports failure without exposing a raw service error.

Best practices

  • Never use MessagingService as the only record of important state.
  • Keep messages small and respect service limits.

Runtime & versions

Luau host; Roblox engine examples require Roblox Studio. Feature availability depends on the language and runtime version used by your project; consult the official reference below.

Luau documentation

Specifications & further reading