Skip to content

Class · inherits Instance

TextChatMessage

Official docs ↗

A data object representing a text chat message.

About TextChatMessage

A data object representing a text chat message.

To learn more about using TextChatMessages, see In-Experience Text Chat.

Properties 11

  • BubbleChatMessageProperties: BubbleChatMessagePropertiesA reference to the BubbleChatMessageProperties that overrides the appearance of this message's chat bubble.

    A reference to the BubbleChatMessageProperties instance that overrides BubbleChatConfiguration properties for this individual message's chat bubble.

    This property is nil by default. It is populated when your TextChatService.OnBubbleAdded callback returns a BubbleChatMessageProperties instance: the returned instance is stored here on the resulting TextChatMessage. Any properties set on it take precedence over the shared BubbleChatConfiguration when the message's bubble is rendered.

  • ChatWindowMessageProperties: ChatWindowMessagePropertiesA reference to the ChatWindowMessageProperties that overrides the appearance of this message in the chat window.

    A reference to the ChatWindowMessageProperties instance that overrides ChatWindowConfiguration properties for this individual message as displayed in the chat window.

    This property is nil by default. It is populated when your TextChatService.OnChatWindowAdded callback returns a ChatWindowMessageProperties instance, typically created with ChatWindowConfiguration.DeriveNewMessageProperties: the returned instance is stored here on the resulting TextChatMessage. Any properties set on it take precedence over the shared ChatWindowConfiguration when the message is rendered.

  • MessageId: stringA unique identifier for the TextChatMessage.
  • Metadata: stringA general purpose field for storing miscellaneous data about the TextChatMessage.

    A general purpose field for storing miscellaneous data about the TextChatMessage. The second argument of TextChannel.SendAsync and TextChannel.DisplaySystemMessage is used to populate this field.

    Use this field to apply additional formatting for special messages within TextChatService.OnIncomingMessage and TextChannel.OnIncomingMessage callbacks.

    local Players = game:GetService("Players")
    local TextChatService = game:GetService("TextChatService")
    
    local customChannel: TextChannel = Instance.new("TextChannel")
    customChannel.Parent = TextChatService:WaitForChild("TextChannels")
    
    customChannel.OnIncomingMessage = function(message: TextChatMessage)
      if string.find(message.Metadata, "Error") then
        local overrideProperties = Instance.new("TextChatMessageProperties")
        overrideProperties.Text = string.format("<font color='rgb(255,0,0)'>%s</font>", message.Text)
        return overrideProperties
      elseif string.find(message.Metadata, "Info") then
        local overrideProperties = Instance.new("TextChatMessageProperties")
        overrideProperties.Text = string.format("<font color='rgb(0, 255, 150)'>%s</font>", message.Text)
        return overrideProperties
      end
    
      return nil
    end
    
    Players.LocalPlayer.CharacterAdded:Connect(function()
      customChannel:DisplaySystemMessage("This is an error!", "Game.Error.Generic")
      customChannel:DisplaySystemMessage("Could not find save data!", "Game.Error.SaveDataNotFound")
    
      customChannel:DisplaySystemMessage("You won the game!", "Game.Info.Win")
      customChannel:DisplaySystemMessage("You lost the game!", "Game.Info.Lose")
    end)
    

    As follows is a reference of the default system messages emitted by the chat system:

  • PrefixText: stringA prefix to add to a user's message.

    A prefix to add to a user's message. This supports Rich Text, so developers can set custom properties for this text to support chat tags.

    By default, TextChatMessage.PrefixText is the name of the TextSource, which is the Player.DisplayName of the user associated with the TextSource via TextSource.UserId.

  • Status: TextChatMessageStatusIndicates the status of the TextChatMessage.
  • Text: stringThe filtered text message for the user.

    The filtered text message for the user. Different users may receive different strings from this property based on filtering rules. It can be an empty string.

  • TextChannel: TextChannelA reference to the origin TextChannel.
  • TextSource: TextSourceA reference to the origin TextSource.
  • Timestamp: DateTimeA timestamp of when the message was originally sent.
  • Translation: stringTranslated and filtered text message.

    Represents translated and filtered text messages based on users' localization settings. The system doesn't translate messages between users with the same localization settings or using languages without the text filter support, so this property can be an empty string if no translation happens. For customization, see Customizing Translated Messages.

TextChatMessage also has every member of Instance. Deprecated and Roblox-only members are hidden.

Reference text from the Roblox Creator Documentation, licensed CC BY 4.0, reorganized by rbxtoolshub.com · Studio 0.743.0.7431133.