This example shows how to use the TextChatService class to design your own frontend. It reuses the default text channels from CreateDefaultTextChannels and is very simple compared to the default UI.
Disable the default UI that comes with the TextChatService by setting the ChatWindowConfiguration.Enabled and ChatInputBarConfiguration.Enabled properties to false in Studio's Properties window.
Create a replacement for the chat input bar. This is the text box that emits messages when the user presses Enter.
Create a ScreenGui and parent it to StarterGui.
Create a TextBox and parent it to the new ScreenGui, then reposition and resize it as desired.
Create a LocalScript and parent it to the new TextBox.
Add the following code to the LocalScript:
Clientlocal TextChatService = game:GetService("TextChatService")-- RBXGeneral is the default public channellocal RBXGeneral = TextChatService:FindFirstChild("TextChannels"):WaitForChild("RBXGeneral")local textBox = script.ParenttextBox.FocusLost:Connect(function(enterPressed)local text = textBox.Textif enterPressed and #text > 0 thenlocal success, response = pcall(function()return RBXGeneral:SendAsync(textBox.Text)end)if not success thenRBXGeneral:DisplaySystemMessage("Failed to send message")end-- Users expect the input box to be cleared after sending a messagetextBox.Text = ""endend)
Create a replacement for the chat window. This is the ScrollingFrame that displays messages as they are received from TextChatService.MessageReceived. This step also creates a UIListLayout to automatically layout the messages.
Create another new ScreenGui and parent it to StarterGui.
Create a ScrollingFrame and parent it to the ScreenGui, then reposition and resize it as desired.
Create a UIListLayout and parent it to the ScrollingFrame.
Create a LocalScript and parent it to the ScrollingFrame.
Add the following code to the LocalScript:
Clientlocal TextChatService = game:GetService("TextChatService")-- Function to create a new text label for each message receivedlocal function addMessageGui(textChatMessage: TextChatMessage)local isOutgoingMessage = textChatMessage.Status == Enum.TextChatMessageStatus.Sendinglocal parent = script.Parentlocal originalLabel = parent:FindFirstChild(textChatMessage.MessageId)if originalLabel thenoriginalLabel.Text = textChatMessage.TextoriginalLabel.BackgroundTransparency = if isOutgoingMessage then 0.5 else 0elselocal textLabel = Instance.new("TextLabel")textLabel.BorderSizePixel = 0textLabel.Font = Enum.Font.BuilderSanstextLabel.TextSize = 18textLabel.TextXAlignment = Enum.TextXAlignment.LefttextLabel.BackgroundTransparency = if isOutgoingMessage then 0.5 else 0textLabel.BackgroundColor3 = Color3.fromRGB(0, 0, 0)textLabel.TextColor3 = Color3.fromRGB(255, 255, 255)textLabel.Name = textChatMessage.MessageIdtextLabel.AutomaticSize = Enum.AutomaticSize.XYtextLabel.Text = textChatMessage.TexttextLabel.Parent = parentendend-- Start listening for incoming messagesTextChatService.MessageReceived:Connect(addMessageGui)