Chat

Show Deprecated
Not Creatable
Service
Not Replicated

The Chat service houses the Lua code responsible for running the Lua Chat System. Similar to StarterPlayerScripts, default objects like Scripts and ModuleScripts are inserted into the service.

In addition to housing the Lua Chat System, this service also exposes functions used to filter text: FilterStringAsync() and FilterStringForBroadcast(). Note that games which implement custom chat systems must use these functions to filter chat properly. See Text and Chat Filtering for more information.

Summary

Properties

Determines whether player's chat messages will appear above their in-game avatar.

Toggles whether the default chat framework should be automatically loaded when the game runs.

Events

Chatted(part: Instance, message: string, color: ChatColor): RBXScriptSignal  

Fires when Chat:Chat() is called.

Methods

Chat(partOrCharacter: Instance, message: string, color: ChatColor): void  

Fires the Chat.Chatted event with the parameters specified in this method.

ChatLocal(partOrCharacter: Instance, message: string, color: ChatColor): void  


InvokeChatCallback(callbackType: ChatCallbackType, callbackArguments: Tuple): Tuple  

Invoke a chat callback function registered by RegisterChatCallback. Used by the Lua Chat System.

RegisterChatCallback(callbackType: ChatCallbackType, callbackFunction: function): void  

Register a function to be called upon the invocation of some chat system event (InvokeChatCallback).

SetBubbleChatSettings(settings: Variant): void  

Customizes various settings of the in-game bubble chat.

CanUserChatAsync(userId: number): boolean  YIELDS

Will return false if the player with the specified Player.UserId is not allowed to chat because of their account settings.

CanUsersChatAsync(userIdFrom: number, userIdTo: number): boolean  YIELDS

Will return false if the two users cannot communicate because their account settings do not allow it.

FilterStringAsync(stringToFilter: string, playerFrom: Player, playerTo: Player): string  YIELDS

Filters a string sent from a player to another player using filtering that is appropriate to the players' account settings.

FilterStringForBroadcast(stringToFilter: string, playerFrom: Player): string  YIELDS

Filters a string sent from a player meant for broadcast to no particular target. More restrictive than Chat:FilterStringAsync().

Properties

BubbleChatEnabled

If true, entering a message in the chat will result in a chat bubble popping up above the player's Player.Character. This behavior can either be enabled by directly ticking this checkbox in Studio, or by using a LocalScript:


1local ChatService = game:GetService("Chat")
2ChatService.BubbleChatEnabled = true
3

This must be done on the client, toggling this value in a server-side Script will have no effect.

LoadDefaultChat

Toggles whether the default chat framework should be automatically loaded when the game runs.

Events

BubbleChatSettingsChanged

Roblox Script Security

Parameters

settings: Variant

Chatted

Fires when Chat:Chat() is called.

Parameters

part: Instance
message: string
color: ChatColor

Methods

Chat

void

The Chat function fires the Chat.Chatted event with the parameters specified in this method.

By default, there is a LocalScript inside of each player's PlayerScripts object named BubbleChat, which causes a dialog-like billboard to appear above the partOrCharacter when the chatted event is fired.

Note: Since dialogs are controlled by a LocalScript, you will not be able to see any dialogs created from this method unless you are running in Play Solo mode.

Parameters

partOrCharacter: Instance

An instance that is the part or character which the BubbleChat dialog should appear above.

message: string

The message string being chatted.

color: ChatColor

An ChatColor specifying the color of the chatted message.

Default Value: "Blue"

Returns

void

No return.

Code Samples

Chat:Chat

1local ChatService = game:GetService("Chat")
2
3local part = Instance.new("Part")
4part.Anchored = true
5part.Parent = workspace
6
7ChatService:Chat(part, "Blame John!", "Red")

ChatLocal

void
Roblox Script Security

Parameters

partOrCharacter: Instance
message: string
color: ChatColor
Default Value: "Blue"

Returns

void

GetShouldUseLuaChat

Roblox Script Security

Returns

InvokeChatCallback

InvokeChatCallback will call a function registered by RegisterChatCallback, given the ChatCallbackType enum and the arguments to send the function. It will return the result of the registered function, or raise an error if no function has been registered.

This function is called by the Lua Chat System so that chat callbacks may be registered to change the behavior of certain features. Unless you are replacing the default Lua Chat System with your own, you should not need to call this function. You can read about the different callback functions at Chat:RegisterChatCallback().

Parameters

callbackType: ChatCallbackType

The type of callback to invoke.

callbackArguments: Tuple

The arguments that will be sent to the registered callback function.


Returns

The values returned by the function registered to the given ChatCallbackType.

RegisterChatCallback

void

RegisterChatCallback binds a function to some chat system event in order to affect the behavior of the Lua chat system. The first argument determines the event (using the ChatCallbackType enum) to which the second argument, the function, shall be bound. The default Lua chat system uses InvokeChatCallback to invoke registered functions. Attempting to register a server- or client- only callback on a peer that isn't a server or client respectively will raise an error. The following sections describe in what ways registered functions will be used.

OnCreatingChatWindow

Client-only. Invoked before the client constructs the chat window. Must return a table of settings to be merged into the information returned by the ChatSettings module.

OnClientFormattingMessage

Client-only. Invoked before the client displays a message (whether it is a player chat message, system message, or /me command). This function is invoked with the message object and may (or may not) return a table to be merged into message.ExtraData.

OnClientSendingMessage

Not invoked at this time.

OnServerReceivingMessage

Server-only. Invoked when the server receives a message from a speaker (note that speakers may not necessarily be a Player chatting). This callback is called with the Message object. The function can make changes to the Message object to change the manner in which the message is processed. The Message object must be returned for this callback to do anything. Setting this callback can allow the server to, for example:

  • Set message.ShouldDeliver to false in order to cancel delivery of the message to players (useful for implementing a chat blacklist)
  • Get/set the speaker's name color (message.ExtraData.NameColor, a Color3) on a message-by-message basis

Parameters

callbackType: ChatCallbackType

The callback to which the function shall be registered (this determines in what way the function is called).

callbackFunction: function

The function to call when the callback is invoked using Chat:InvokeChatCallback.


Returns

void

SetBubbleChatSettings

void

This function customizes various settings of the in-game bubble chat.

Before using this, make sure that bubble chat is enabled by setting Chat.BubbleChatEnabled to true.

The settings argument is a table where the keys are the names of the settings you want to edit and the values are what you want to change these settings to. Note that you don't have to include all of them in the settings argument, omitting some will result in them keeping their default value.

This function is client-side only, attempting to call it on the server will trigger an error.

For a more detailed walkthrough, see Bubble Chat.

Parameters

settings: Variant

A settings table.


Returns

void

No return.

Code Samples

Restore default settings

1local ChatService = game:GetService("Chat")
2
3ChatService:SetBubbleChatSettings({})
Customize visual aspects

1local ChatService = game:GetService("Chat")
2
3ChatService:SetBubbleChatSettings({
4 BackgroundColor3 = Color3.fromRGB(180, 210, 228),
5 TextSize = 20,
6 Font = Enum.Font.Cartoon,
7})

CanUserChatAsync

Yields

Will return false if the player with the specified Player.UserId is not allowed to chat because of their account settings.

Parameters

userId: number

Returns

CanUsersChatAsync

Yields

Will return false if the two users cannot communicate because their account settings do not allow it.

Parameters

userIdFrom: number
userIdTo: number

Returns

FilterStringAsync

Yields

Partial Deprecation Warning: Calling this function from the client using a LocalScript is deprecated, and will be disabled in the future. Text filtering should be done from a Script on the server using the similarly-named TextService:FilterStringAsync(), which uses a different set of parameters and return type.

Games that do not properly filter player-generated text might be subject to moderation action. Please be sure a game properly filters text before publishing it.

FilterStringAsync filters a string using filtering that is appropriate for the sending and receiving player. If the filtered string is to be used for a persistent message, such as the name of a shop, writing on a plaque, etc, then the function should be called with the author as both the sender and receiver.

This function should be used every time a player can enter custom text in any context, most commonly using a TextBox. Some examples of text to be filtered:

  • Custom chat messages
  • Custom character names
  • Names for a shop in a tycoon-style game

Parameters

stringToFilter: string

The raw string to be filtered, exactly as entered by the player.

playerFrom: Player

The author of the text.

playerTo: Player

The intended recipient of the provided text; use the author if the text is persistent (see description).


Returns

FilterStringForBroadcast

Yields

Filters a string sent from playerFrom for broadcast to no particular target. The filtered message has more restrictions than Chat:FilterStringAsync().

Some examples of where this method could be used:

  • Message walls
  • Cross-server shouts
  • User-created signs

Calling FilterString from LocalScripts is deprecated and will be disabled in the future. Text filtering should be done from server-side Scripts using FilterStringAsync.

Note: A game not using this filter function for custom chat or other user generated text may be subjected to moderation action.

Parameters

stringToFilter: string

Message string being filtered.

playerFrom: Player

Instance of the player sending the message.


Returns

Filtered message string.

Code Samples

Chat:FilterStringForBroadcast

1local Players = game:GetService("Players")
2local Chat = game:GetService("Chat")
3
4local playerFrom = Players.LocalPlayer
5local message = "Hello world!"
6
7-- Filter the string and store the result in the 'FilteredString' variable
8local filteredString = Chat:FilterStringForBroadcast(message, playerFrom)
9
10print(filteredString)