Want a special badge and 30 bux? Make some PolyWorld! Content and post it in the Creations forum!
Dark mode is incomplete! Please report any issues to the Discord.

MessageModule

LocalScripts Scripts Not creatable

MessageModule sends data between the server and clients.
Similar to remote events, but as a module instead of Instances.
Available as the global MessageModule.


Overview

Methods

Events


API

Methods

MessageToServer

MessageToServer(name: string, data: any?) : void
LocalScripts only.
Sends a named message to the server.
Listen on the server with MessageFromClient.

-- LocalScript
MessageModule:MessageToServer("tool_use", {
    origin = CameraModule.Position,
    dir = Vector3.new(0, 0, -1),
    charged = true,
    part = workspace:FindFirstChild("Part"),
})

MessageToClient

MessageToClient(player: Player, name: string, data: any?) : void
Scripts only.
Sends a named message to one player.
Listen on that client with MessageFromServer.

-- Script
MessageModule:MessageToClient(player, "round_start", { seconds = 60 })
Events

MessageFromServer

MessageFromServer : Event (name: string, data: any)
LocalScripts only.
Fires when the server calls MessageToClient for the local player.

-- LocalScript
MessageModule.MessageFromServer:Connect(function(name, data)
    if name == "round_start" then
        UI:Hud("Round starts in " .. tostring(data.seconds))
    end
end)

MessageFromClient

MessageFromClient : Event (player: Player, name: string, data: any)
Scripts only.
Fires when a client calls MessageToServer.

-- Script
MessageModule.MessageFromClient:Connect(function(player, name, data)
    if name == "tool_use" then
        print(player.Name, "fired", data)
    end
end)

Data

data can be a table, number, string, bool, Vector3, Color3, or Part.

Tables may nest those types (and integer or string keys). Parts are sent by id and
show up on the other side only if that Part already exists there. Local-only Parts
are dropped (nil).

-- Script
MessageModule.MessageFromClient:Connect(function(player, name, data)
    if name == "tool_use" and data.part then
        print(player.Name, "hit", data.part.Name)
    end
end)

Notes

Prefer MessageModule over older FireServer / script.OnRemoteEvent for new work.
Those older remotes remain for compatibility.