Skip to content

Chat

System · Chat · server and client scripts

Chat sends player chat messages, posts system announcements, shows chat bubbles, runs server slash commands and delivery filters, and fires signals when chat events arrive.

MaxLength

PropertyRead only
MaxLength: number

MaxLength is the longest chat message, system announcement, or chat bubble in bytes (200).

Example

-- Server script.
local text = "Round starting!"
if #text <= Chat.MaxLength then
    Chat.Announce(text)
end

Send

FunctionClient only
Send(text: string) -> ()

Send sends a chat message as the local player. Only client scripts may call it. Blank strings are ignored; strings longer than MaxLength bytes or containing NUL bytes raise an error.

Example

-- Client script.
Chat.Send("Ready!")
Errors (1)
Error When
Send can only be called from a client script Called from a server script.

Announce

Function
Announce(text: string, options: ChatAnnounceOptions?) -> ()

Announce delivers a system announcement without running the chat safety filter. Blank strings are ignored; strings longer than MaxLength bytes or containing NUL bytes raise an error. Pass options.Color as a Color with finite channels in 0..1 to tint the announcement.

On the server, pass options.To as a player or a list of players (omit it to reach everyone; an empty list {} sends to nobody). On a client, Announce fires Announced locally and rejects options.To.

Example

-- Server script.
Chat.Announce("Round starting!", { Color = Color.new(1, 0.85, 0.2) })

Announced

EventClient onlyRead only
Announced: Signal<(text: string, color: Color?) -> ()>

Announced fires on clients with (text, color) for each system announcement and engine notice (color is nil for engine notices and announcements sent without options.Color).

Example

-- Client script.
Chat.Announced:Connect(function(text, color)
    print(text, color)
end)
Errors (1)
Error When
Announced can only be written from a client script Written from a server script.

MessageSent

EventRead only
MessageSent: Signal<(player: Entity, text: string, color: Color) -> ()>

MessageSent fires on both the server and clients with (player, text, color) after a player's chat message passes the safety filter, where color is the player's name color.

Example

-- Server script.
Chat.MessageSent:Connect(function(player, text, color)
    print(player.Name, text, color)
end)

Command

FunctionServer only
Command(name: string, handler: (player: Entity, args: string) -> ()) -> Connection

Command registers a slash command and returns a Connection. When a player sends /name args, the server calls handler(player, args) with the text after the first run of spaces or tabs and does not broadcast the message or fire MessageSent. Command matching ignores ASCII letter case, and any unregistered /word message relays as ordinary chat.

name must be 1 to 32 ASCII letters, digits, _, or -, without a leading /. Registering a name that is already registered raises an error. Calling :Disconnect() or stopping or reloading the owning script removes the command.

Example

-- Server script.
local conn = Chat.Command("ping", function(player, args)
    Chat.Announce("Pong " .. args, { To = player })
end)
Errors (1)
Error When
Command can only be called from the server Called from a client script.

SetDelivery

FunctionServer only
SetDelivery(fn: ChatDelivery) -> Connection

SetDelivery installs a recipient filter for chat messages after the safety filter runs and returns a Connection. Only one delivery hook is active at a time; calling SetDelivery again replaces the previous hook. Calling :Disconnect() or stopping or reloading the owning script restores delivery to everyone.

The hook runs as fn(sender, text) without yielding and returns true (every player), false (nobody), or a list of player entities. A hook that yields, raises an error, or returns another value drops the message. Server MessageSent still fires for every message that passes the safety filter, even when the hook drops it.

Example

-- Server script.
local conn = Chat.SetDelivery(function(sender, text)
    return true
end)
Errors (1)
Error When
SetDelivery can only be called from the server Called from a client script.

ShowBubble

Function
ShowBubble(entity: Entity, text: string) -> ()

ShowBubble displays a chat bubble above an entity without running the chat safety filter. Passing a player targets that player's character and does nothing when the player has no character; any other entity must have a Position. Blank strings are ignored; strings longer than MaxLength bytes or containing NUL bytes raise an error.

On the server, ShowBubble broadcasts the bubble to clients. On a client, it fires BubbleShown locally.

Example

-- Server script.
Chat.ShowBubble(self, "Welcome!")

BubbleShown

EventClient onlyRead only
BubbleShown: Signal<(entity: Entity, text: string) -> ()>

BubbleShown fires on clients with (entity, text) for each ShowBubble call and for each received player chat message whose speaker has a character.

Example

-- Client script.
Chat.BubbleShown:Connect(function(entity, text)
    print(entity.Name, text)
end)
Errors (1)
Error When
BubbleShown can only be written from a client script Written from a server script.

Filter

FunctionServer only
Filter(player: Entity, text: string, options: FilterOptions?) -> (FilterStatus, string?)

Filter runs player-authored text through the chat safety filter and yields until it answers, returning (status, filteredText). status is "Ok", "Rejected", "RateLimited", "Unavailable", or "TimedOut". Only "Ok" returns filtered text; every other status returns nil.

Pass options.Timeout as a finite number of seconds above 0 (10 by default). Each player has a dedicated filter bucket of 10 tokens refilling at 5 per second; calling Filter when the bucket is empty returns ("RateLimited", nil) immediately. In local test mode with no backend configured, Filter returns ("Ok", text) immediately.

Example

-- Server script.
Chat.Command("me", function(player, args)
    local status, text = Chat.Filter(player, args)
    if status ~= "Ok" or text == nil then
        return
    end
    local line = player.Name .. " " .. text
    if #line <= Chat.MaxLength then
        Chat.Announce(line)
    end
end)
Errors (1)
Error When
Filter can only be called from the server Called from a client script.