How can I hide a message if it contains a certain string?
I want to make custom commands so if the message contains “/” then it should not be visible to the text box nor the bubble chat.
P.S. I am using the new TextChatService
How can I hide a message if it contains a certain string?
I want to make custom commands so if the message contains “/” then it should not be visible to the text box nor the bubble chat.
P.S. I am using the new TextChatService
The following code will make a message not show up in the chat when the message starts with /
:
local TextChatService = game:GetService("TextChatService")
TextChatService.OnIncomingMessage = function(message: TextChatMessage)
if string.sub(message.Text, 1, 1) == "/" then
local newProperties = Instance.new("TextChatMessageProperties")
newProperties.Text = " "
return newProperties
end
end
This will have to be placed in a LocalScript in order to work.
In case you want to filter messages on the server (possibly for only some people / some channels) I suggest you to take a look at the ShouldDeliverCallback.
I prefer it to be server sided but game:GetService("TextChannel")
is unavailable and the only way to access the ShouldDeliverCallback is from that. Is there any workaround for this?
This is how you would get the “RBXGeneral” TextChannel
:
TextChatService:WaitForChild("TextChannels").RBXGeneral
There is actually a full guide on how to use ShouldDeliverCallback
: