Since ROBLOX hasn’t explicitly shown how to migrate old custom chat systems to the new TextChatService, and I haven’t seen any tutorials showing how to create a basic custom chat using it yet. I thought I would just do it myself.
Benefits of using TextChatService
- ROBLOX will automatically filter chat messages for you.
- ROBLOX will handle chat moderation for you.
- ROBLOX will automatically handle age checks and chat permissions for you.
Steps on how to create a custom chat system using TextChatService
This tutorial does not show you how to make a good looking custom chat GUI, it only shows how to create a very basic chat GUI and how to make it work with TextChatService using some simple scripting logic.
Basic Barebones GUI Section
1. Start by creating a ScreenGui in StarterGui. Name it CustomChat.
2. Add a ScrollingFrame into the ScreenGui you just made. Change the Size, BackgroundTransparency, and other properties to whatever you want.
3. Add a TextLabel to the ScrollingFrame, make sure to name it DefaultChatMessage.
4. Add a UIGridLayout to the ScrollingFrame. Adjust CellPadding to something like {0.01, 0},{0.01, 0} and CellSize to something like {1, 0},{0.05, 0}, so new messages will be automatically sorted into position. Duplicate your DefaultChatMessage instance to make sure CellPadding and CellSize are what you want. Delete the duplicate “DefaultChatMessage” when you are done.
5. Set the visible property of your DefaultChatMessage to be false.
Scripting Section
1. Start by creating a script with a RunContext of client. Name it whatever you want. Parent it where most convenient.
2. Next, create local variables for TextChatService, TextChannels, and RBXDefault. Add them to the top of your empty script.
local TextChatService = game:GetService("TextChatService")
local TextChannels = TextChatService:WaitForChild("TextChannels")
local RBXGeneral = TextChannels:WaitForChild("RBXGeneral")
3. Add a MessageReceived connection for RBXGeneral
RBXGeneral.MessageReceived:Connect(function(incomingMessage: TextChatMessage)
--scripting logic will go here
end)
4. Add basic scripting logic to your MessageReceived connection to get your finished script
local TextChatService = game:GetService("TextChatService")
local TextChannels = TextChatService:WaitForChild("TextChannels")
local RBXGeneral = TextChannels:WaitForChild("RBXGeneral")
RBXGeneral.MessageReceived:Connect(function(incomingMessage: TextChatMessage)
local PlayerWhoSentMessage=game.Players:FindFirstChild(incomingMessage.TextSource.Name)
local ChatMessage=incomingMessage.Text --automatically filtered
if PlayerWhoSentMessage~=nil then --only add a new message if the player is found
local MessageBoxClone=game.Players.LocalPlayer.PlayerGui.CustomChat.ScrollingFrame.DefaultChatMessage:Clone() --Clone the empty DefaultChatMessage
MessageBoxClone.Text=PlayerWhoSentMessage.Name..": "..ChatMessage --Add player name and text
MessageBoxClone.Parent=game.Players.LocalPlayer.PlayerGui.CustomChat.ScrollingFrame --Parent it to your custom chat scrolling frame
MessageBoxClone.Visible=true --Make it visible so you can actually see it
end
end)
See? It’s actually quite simple to use TextChatService for a custom chat system! You can add additional logic, such as checking a player’s team, to create features like a police radio!
It will automatically capture chat input as long as RBXDefault is set as the default TextChannel (which it is by default), so no custom chat input is required.
But if you want to make a custom chat input you would use TextChannel:SendAsync in a LocalScript. You can use RBXDefault as the TextChannel for this.
You would then get the output from the MessageReceived connection to RBXDefault.