Hi, since Roblox now requires everyone to move to the newer TextChatService I’ve faced same issues just like everyone else who are using Legacy Chat system. I have managed to change my code to adapt to these new Roblox changes, and so I want to share my experiences with you and some advices for parts that were difficult for me to understand or implement. I’ll provide some code lines examples as well that you may want to use for your custom chat system.
The very first thing that I have struggled with is understanding the concept of TextChatService, understanding how it works and what are the obvious differences from Legacy Chat functionality.
First off, I was unsure how to implement Chat text filtering which was essential for Legacy Chat. I have ended up looking up wrong things such as TextService which is NOT what you or I need for a communication chat system.
The answer to my question was simple and straightforward: TextChatService does not require you to send client message to server for filtering and then send it back from server to client.
This answer can be found here: In-Experience Text Chat System | Documentation - Roblox Creator Hub
The second part that I’ve struggled with was getting a working code, since this system works a bit different than Legacy Chat I had to imagine how the message sending and receiving workflow looks like. This was actually pretty simple, in fact even simpler than the Legacy Chat system, because all you need is a send message function and a receive message function and both of these functions run on client, no server side scripts involved.
Third part was actually writing code, mostly just changing some of my already existing chat system code lines. Now the first thing you want in your chat system script is to have this line:
local TextChatService = game:GetService('TextChatService')
This line is needed for both - the script that sends message and the script that retrieves messages. Now you can do your chat system your own way, perhaps use just one script or even more, just make sure that you’re using game:GetService('TextChatService')
and not game:GetService('TextService')
or game:GetService('Chat')
Moving on to the more important function lines, I needed to get rid of RemoteEvents and chatted:FireServer(TextMessage)
stuff as well as Chat Controller script which was residing in ServerScriptService.
To send messages from client to all other clients in the server (text filters are included as well) all you need to do is use a code line like this:
TextChatService.TextChannels.RBXGeneral:SendAsync(TextMessage)
Now the important things to note: RBXGeneral stands for a Text Channel name (you need to replace it with your TextChannel name if you are using custom made channels), unlike Legacy Chat, TextChatService have multiple Text Channels and you must choose which one you want to use (or create your own) and you can also use multiple different Text Channels if you need a private chat between two players and a public chat for all server.
How these Text Channels work? This one question I had in mind at first when reading TextChatService Documentation. Text Channels can be created automatically if you choose in your game on Roblox Studio in Explorer window find TextChatService and after you click on it check the Properties window for CreateDefaultTextChannels property, make sure it is ticked to receive the default Text Channels in game such as RBXGeneral.
You can create your own Text Channels instead of using Roblox default channels, however this is something I have opted out of doing myself for now and I will not cover it in this thread, but you can find it in official Roblox Documentation website: TextChannel | Documentation - Roblox Creator Hub
Now we know that messages can be sent using:
TextChatService.TextChannels.RBXGeneral:SendAsync(TextMessage)
However, we need to retrieve these messages somehow. With TextChatService the client can receive signals of new incoming message without the need of RemoteEvents or server side script that would act as a medium between clients. After long time spent doing Google searches I’ve found this line which is essential to receive messages:
TextChatService.OnIncomingMessage = function(message:TextChatMessage)
This line fires pretty much every time someone in server sends a message, but it fires twice!
Now why does this function fire twice when we send only one message? I’ve done my research using print(message) and found that we receive 2 different message.Status results, the first one being Enum.TextChatMessageStatus.Sending and the second one Enum.TextChatMessageStatus.Success. I have resolved this issue by using the following code line:
if message.TextSource and message.Status == Enum.TextChatMessageStatus.Success then
Now perhaps message.TextSource is not needed (?) but I do want too check for it in case if message somehow doesn’t have its sender name.
You might be asking what is message.TextSource well it is the player name of who sent the message, in other words the player name that you have to use at the start of the message text to indicate who sent it.
The last few important things you need to know is how to retrieve the message text and its sender name.
message.Text - - the chat message text context
message.TextSource - - the name of player who sent the chat message
These two are required code parts you need to use for displaying the message text and player who sent it name on the screen.
But there’s a slight catch, both message.Text and message.TextSource are Instances and NOT string results.
What you need to do in this case is use these two code lines:
local text = tostring(message.Text)
local sender = tostring(message.TextSource)
With these you will be able to use text variable to define the chat message text content and sender variable to show who have sent this message.
This is pretty much all I needed to make it function properly, it looks short and simple but took me hours to understand and find needed information as some things such as how to receive an incoming message is not explained very well by Roblox Documentation.
I hope this little thread will help someone who also run into these troubles migrating custom chat system into TextChatService compliant chat.
Please take note that these are just merely tips for making a custom chat implementing TextChatService, this is not a full tutorial on how to make a working chat system.