Modify the Player's Chat Message

If it wasn’t obvious, let me explain:

I have this word, and let’s call it a BONUS WORD: “Added”.

So, a player chatted “Sample Text”, and I want to make a script that changes that message “Sample Text” to “Sample Text Added”, basically add that BONUS WORD to the player’s message. Is it possible? Because I’ve seen several games do so. AND IT DOESN’T HAVE TO BE NECESSARILY “Sample Text”, it could be anything.

If you don’t want to write an entire script completing this operation, at least give me a better understanding on how I accomplish it.

I will appreciate all kinds of help, thank you.

2 Likes

In the light of the still fairly new TextChatService, I suggest taking a look at the flowchart displayed on this page: In-Experience Text Chat System | Documentation - Roblox Creator Hub.

As you can see, there are two signals to consider:

  1. SendingMessage,
  2. OnIncomingMessage.

The latter can intercept the message before it is displayed on the recipients’ side, while the first one enables us to handle the text during the sending process and right before the placeholder message is replaced by whatever was sent to all other clients.

Example in the ‘general’ chat.

local TextChatService = game:GetService("TextChatService")
local rbxGeneralChannel = TextChatService:WaitForChild("TextChannels"):WaitForChild("RBXGeneral")

rbxGeneralChannel.OnIncomingMessage = function(textChatMessage)
	local textChatMsgProperties = Instance.new("TextChatMessageProperties")
	
	if #textChatMessage.Text > 0 then
		textChatMsgProperties.Text = textChatMessage.Text .." [added]"
	end
	return textChatMsgProperties
end
Additional SendingMessage - probably more noticable during high ping times.
local TextChatService = game:GetService("TextChatService")
local rbxGeneralChannel = TextChatService:WaitForChild("TextChannels"):WaitForChild("RBXGeneral")

TextChatService.SendingMessage:Connect(function(textChatMessage)
	local textChatMsgProperties = Instance.new("TextChatMessageProperties")
	print(textChatMessage.TextChannel)
	
	if textChatMessage.TextChannel == rbxGeneralChannel and #textChatMessage.Text > 0 then
		textChatMsgProperties.Text = textChatMessage.Text .." [added]"
	end
	return textChatMsgProperties
end)

Keep in mind that these are client scripts, so chat tags and edits are done locally, as opposed to what we used to do with the legacy chat modules.

I believe this should be enough to add a check for certain words combinations or phrases as well.

Alright, thanks for helping, that method worked just fine.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.