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.
As you can see, there are two signals to consider:
SendingMessage,
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.
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.