I spent way too long trying to figure out how to use the new TextChatService to display messages from scripts and even longer trying to figure out how to style them differently from other chat messages, so this will be a short guide on sending messages from scripts to players’ chats.
First off, make sure you are using the new TextChatService. I won’t tell you how to do it here because it is the default for new games, and there are guides on switching to it if you need to.
Here is the short and sweet LocalScript I use to display messages in players’ chats.
local TextChatService = game:GetService("TextChatService")
game.ReplicatedStorage.RemoteEvents.MessageEvent.OnClientEvent:Connect(function(msg)
TextChatService.TextChannels.RBXGeneral:DisplaySystemMessage(msg)
end)
You can send messages in server scripts too but I did it this way so I can easily send messages to a single player or all players at once using a RemoteEvent.
Styling the messages is super simple. You can just use Rich Text Markup in the string of your message to change its appearance. I couldn’t find this anywhere, but I may have just missed it. Here is a short example of how it works.
local TextChatService = game:GetService("TextChatService")
TextChatService.TextChannels.RBXGeneral:DisplaySystemMessage("You won <stroke color='#00A2FF' joins='miter' thickness='2' transparency='0.25'>25 gems</stroke>.")
This is straight from the Rich Text Markup example and there is so much more you can do with it. Here is how it looks in game.
I know this is a very simple guide, but hopefully is will help someone else save some time in the future.