Customizing Text Chat

*Nội dung này sẽ sớm có sẵn bằng ngôn ngữ bạn chọn.

The in-experience text chat system, powered by TextChatService, allows players to easily communicate and socialize with each other in live experiences. In addition to supporting the default text chat, you can customize the front‑end user interface.

Chat Window Configuration

The overall chat window consists of the chat window, an input bar, and optional channel tabs.

Core components of the text chat window.

The channel tabs are disabled by default and each component can be toggled on/off in Studio or through scripting:

Directly in Studio's Explorer window, expand the TextChatService branch and select ChatWindowConfiguration, ChatInputBarConfiguration, or ChannelTabsConfiguration. Then, in the Properties window, enable or disable the component.

When ChannelTabsConfiguration is enabled, each default TextChannel will appear in a tab as outlined in the following table. In addition, each custom TextChannel will create a tab corresponding to the channel's Name property.

Default ChannelTab Name
RBXGeneralGeneral
RBXSystemGeneral (combined into a single tab with RBXGeneral)
RBXTeamTeam
RBXWhisperUser name of other player

Window Appearance

Appearance of the overall chat window is customizable through ChatWindowConfiguration.

ChatWindowConfiguration instance in Explorer hierarchy.
PropertyDescriptionDefault
BackgroundColor3Color3 background color of the chat window.[25, 27, 29]
BackgroundTransparencyTransparency of the chat window's background.0.3
FontFaceFont of chat window text.BuilderSansMedium
TextColor3Color3 of chat window text.[255, 255, 255]
TextSizeSize of chat window text.14
TextStrokeColor3Color3 of the stroke for chat window text.[0, 0, 0]
TextStrokeTransparencyTransparency of the stroke for chat window text.0.5
HorizontalAlignmentHorizontal alignment of the chat window.Left
VerticalAlignmentVertical alignment of the chat window.Top
HeightScaleHeight scale of the chat window relative to the screen size.1
WidthScaleWidth scale of the chat window relative to the screen size.1

Input Bar Appearance

Appearance of the chat input bar is customizable through ChatInputBarConfiguration.

ChatInputBarConfiguration instance in Explorer hierarchy.
PropertyDescriptionDefault
BackgroundColor3Color3 background color of the chat input bar.[25, 27, 29]
BackgroundTransparencyTransparency of the chat input bar's background.0.2
FontFaceFont of chat input text.BuilderSansMedium
PlaceholderColor3Color3 of placeholder chat input text.[178, 178, 178]
TextColor3Color3 of player-entered chat input text.[255, 255, 255]
TextSizeSize of chat input text.14
TextStrokeColor3Color3 stroke color of chat input text.[0, 0, 0]
TextStrokeTransparencyTransparency of the stroke for chat input text.0.5
AutocompleteEnabledWhether the text chat system shows autocomplete options for emojis and commands. Emojis are autocompleted by typing : followed by non-whitespace characters, while commands are autocompleted by typing /.true
KeyboardKeyCodeAdditional key players can press to trigger focusing on the default chat input bar.Slash

Channel Tabs Appearance

Appearance of the channel tabs is customizable through ChannelTabsConfiguration.

ChannelTabsConfiguration instance in Explorer hierarchy.
PropertyDescriptionDefault
BackgroundColor3Color3 background color of the channel tabs.[25, 27, 29]
BackgroundTransparencyTransparency of the channel tabs' background.0
HoverBackgroundColor3Color3 background color of tabs when hovering over them.[125, 125, 125]
FontFaceFont for the text in channel tabs.BuilderSansBold
TextColor3Color3 of text in an unselected tab.[175, 175, 175]
SelectedTabTextColor3Color3 of text in a selected tab.[255, 255, 255]
TextSizeSize of the text in channel tabs.18
TextStrokeColor3Color3 stroke color of the text in channel tabs.[0, 0, 0]
TextStrokeTransparencyTransparency of the stroke for text in channel tabs.1

Customizing Messages

You can customize the appearance of chat message bodies and prefixes using ChatWindowMessageProperties and TextChatService.OnChatWindowAdded callbacks without overriding the existing UI. The customization options let you modify the appearance of chat messages to match your experience's theme, and you can also sort or highlight messages from different user groups by adding chat tags and coloring prefixes.

Coloring User Names

When a user sends a chat message, their DisplayName displays as the prefix portion of the message. By default, each user's name is colored according to their Player.TeamColor but you can change the colors of chat names using ChatWindowMessageProperties and OnChatWindowAdded. The following LocalScript in StarterPlayerScripts assigns a predetermined color to each user, picking randomly from a table of RGB colors.

Colored user name in the chat window.
LocalScript - Random User Name Colors

local TextChatService = game:GetService("TextChatService")
local chatWindowConfiguration = TextChatService.ChatWindowConfiguration
local nameColors = {
Color3.fromRGB(255, 0, 0),
Color3.fromRGB(0, 255, 0),
Color3.fromRGB(0, 0, 255),
Color3.fromRGB(255, 255, 0),
}
TextChatService.OnChatWindowAdded = function(message: TextChatMessage)
local properties = chatWindowConfiguration:DeriveNewMessageProperties()
local textSource = message.TextSource
if textSource then
local index: number = (textSource.UserId % #nameColors) + 1
local randomColor: Color3 = nameColors[index]
properties.PrefixTextProperties = chatWindowConfiguration:DeriveNewMessageProperties()
properties.PrefixTextProperties.TextColor3 = randomColor
end
return properties
end

You can also apply color and transparency gradients to color message prefixes using UIGradient.

Gradient user name in the chat window.
Gradient User Name Colors

local TextChatService = game:GetService("TextChatService")
local chatWindowConfiguration = TextChatService.ChatWindowConfiguration
local gradient = Instance.new("UIGradient")
gradient.Color = ColorSequence.new{
ColorSequenceKeypoint.new(0, Color3.fromRGB(255, 0, 0)),
ColorSequenceKeypoint.new(0.5, Color3.fromRGB(255, 255, 0)),
ColorSequenceKeypoint.new(1, Color3.fromRGB(255, 0, 255))
}
TextChatService.OnChatWindowAdded = function(message: TextChatMessage)
local properties = chatWindowConfiguration:DeriveNewMessageProperties()
local textSource = message.TextSource
if textSource then
properties.PrefixTextProperties = chatWindowConfiguration:DeriveNewMessageProperties()
gradient:Clone().Parent = properties.PrefixTextProperties
end
return properties
end

Adding Chat Tags

If your experience has users with special attributes like VIP status, you can attach chat tags wrapped in brackets to the front of user messages to highlight their messages. The following LocalScript in StarterPlayerScripts examines all Player instances representing users in your experience and appends VIP chat tags to those with the IsVIP attribute.

VIP chat tag appended to user name in the chat window.
Appending Chat Tags

local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players")
local chatWindowConfiguration = TextChatService.ChatWindowConfiguration
TextChatService.OnChatWindowAdded = function(message: TextChatMessage)
local properties = chatWindowConfiguration:DeriveNewMessageProperties()
if message.TextSource then
local player = Players:GetPlayerByUserId(message.TextSource.UserId)
if player:GetAttribute("IsVIP") then
properties.PrefixText = "[VIP] " .. message.PrefixText
properties.PrefixTextProperties = chatWindowConfiguration:DeriveNewMessageProperties()
properties.PrefixTextProperties.TextColor3 = Color3.fromRGB(255, 125, 50)
end
end
return properties
end

Rich Text Customization

Rich text font color tags can be used to format chat messages, helpful if you want to apply formatting to very specific parts of the message. Note that rich text does not support gradients, but the following code sample shows how you can move the user name (stored in TextChatMessage.PrefixText) into the message body and then apply rich text tagging to only the name portion.

Rich text customization of user name in the chat window.
Rich Text Customization

local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players")
local chatWindowConfiguration = TextChatService.ChatWindowConfiguration
local gradient = Instance.new("UIGradient")
gradient.Color = ColorSequence.new{
ColorSequenceKeypoint.new(0, Color3.fromRGB(255, 0, 0)),
ColorSequenceKeypoint.new(0.5, Color3.fromRGB(255, 255, 0)),
ColorSequenceKeypoint.new(1, Color3.fromRGB(255, 0, 255))
}
TextChatService.OnChatWindowAdded = function(message: TextChatMessage)
local properties = chatWindowConfiguration:DeriveNewMessageProperties()
if message.TextSource then
properties.PrefixText = "[VIP]"
properties.Text = string.format("<font color='#00ffff'>%s</font>", message.PrefixText) .. " " .. message.Text
properties.PrefixTextProperties = chatWindowConfiguration:DeriveNewMessageProperties()
gradient:Clone().Parent = properties.PrefixTextProperties
end
return properties
end

Sending Messages from Non‑Player Sources

In certain design scenarios, you may want to show non‑player dialogue in the chat window, such as "speech" from a public address system or a non‑player character.

System

To deliver an unstyled system message to the local player, simply call DisplaySystemMessage() from the default RBXGeneral channel with a prefix before the player's display name.

Client Script

local Players = game:GetService("Players")
local TextChatService = game:GetService("TextChatService")
local player = Players.LocalPlayer
local generalChannel: TextChannel = TextChatService:WaitForChild("TextChannels").RBXGeneral
local PREFIX = "[Guide] Welcome "
-- Send "system message" to player with their display name appended
generalChannel:DisplaySystemMessage(PREFIX .. player.DisplayName)
Image showing a basic system message in the chat window.

NPC/Object

You can also stylize non-player dialogue and add chat bubbles to make it appear like messages are coming from an NPC or object within the 3D world.

Client Script

local TextChatService = game:GetService("TextChatService")
local generalChannel: TextChannel = TextChatService:WaitForChild("TextChannels").RBXGeneral
TextChatService.OnIncomingMessage = function(textChatMessage: TextChatMessage)
local properties = Instance.new("TextChatMessageProperties")
-- Check for system messages that contain metadata
if not textChatMessage.TextSource and textChatMessage.Metadata ~= "" then
-- Add prefix to make message look like it was sent by a player
properties.PrefixText = string.format("<font color='#%s'>%s: </font>", "#50C999", textChatMessage.Metadata)
-- Add bubble chat
TextChatService:DisplayBubble(workspace.Statue, textChatMessage.Text)
end
return properties
end
local message = "Welcome! I will be your guide."
local speakerName = "Ancient Knight"
generalChannel:DisplaySystemMessage(message, speakerName)
Image showing a knight statue NPC broadcasting a chat message to the chat window, along with a chat bubble above its head.