How to migrate your Legacy Chat to TextChatService

Hello,

I’m still unsure on how I should send messages. What would the code possibly look like. I’m not asking for an entire script write, only small snippets to get me started.

It should be used in local script. Roblox chat services will filter out the message and return it back to all clients.

1 Like

Let’s say you have a TextBox class object which you will use to write messages:
We will name this object “chatline”

chatline.FocusLost:connect(function(inputObject)
	TextChatService.TextChannels.RBXGeneral:SendAsync(chatline.Text)
end)

Here in this short function whenever your TextBox loses focus (player clicks Enter button or exits TextBox) it will send all written text inside this TextBox to the TextChatService which will filter out the message and send it back to all other clients.
What you need to do then is display these messages for clients:

TextChatService.OnIncomingMessage = function(message:TextChatMessage)
	if message.TextSource and message.Status == Enum.TextChatMessageStatus.Success then
	--The part where you add your code for displaying message
		local text = message.Text  --message text
		local sender = message.TextSource.Name  --player who sent name
	end
end

All you have to do is either create new or clone TextLabel or Frame with TextLabels inside it and place them every time on player UI to display the messages. The TextLabel text should be replaced with message.Text and message.TextSource.Name contents to display message and player who sent it name.

1 Like