How to prevent the players message from showing in chat?

I have a admin system that requires the player to speak in the chat, but I don’t know how to prevent the players message to be sent in the chat. I’ve tried every single way that the dev forum could offer but nothing worked.

2 Likes

Check out this, The message will still appear to the player who sent it, but to no-one else
(under “ShouldDeliverCallback”)

1 Like

Use TextChatService.OnIncomingMessage, in a LocalScript within StarterPlayerScripts. Check if message.TextSource is an Admin, and the text chat starts with the command prefix. If both conditions pass, set the Text to “”, and the client shouldn’t receive the message.

It should be noted that this still replicates the message to the server, it just doesn’t show it for clients. This is a better alternative because it also doesn’t show for the player who sent the command, unlike what @Claym1x suggested.

If your admin system consist of Chat Commands, you can use TextChatCommands. If TextChatCommands don’t work for your use case, use either of the other solutions provided already

I think the only way to prevent the admin command (im assuming thats what you mean) is to use the prefix “/”

This is what I’ve used to try to stop the message from being sent, but the player and other clients can still see the message. Ideally, I want every player not able to see the message, which is what you pointed out. I’m sure that I wrote my code correctly so I cant see anything wrong about it.

The remote, “adminCommandRequest” returns true once the command is correctly written out.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players")

local player = Players.LocalPlayer
local remotes = ReplicatedStorage:WaitForChild("Remotes")
local adminCommandRequest = remotes:WaitForChild("AdminCommandRequest")

TextChatService.OnIncomingMessage = function(message: TextChatMessage)
	if message.Status == Enum.TextChatMessageStatus.Success then
		local properties = Instance.new("TextChatMessageProperties")
		properties.Text = message.Text

		local stringSplit = string.split(properties.Text, " ")

		for i, newString in stringSplit do
			stringSplit[i] = string.gsub(newString, "_", " ")
		end


		if adminCommandRequest:InvokeServer(message.TextSource.UserId,stringSplit) == true then
			properties.Text = ""
			return properties
		end
		
		return properties
	end
end

Do it before the TextChatMessageStatus is already on Success. This means remove that if statement. Success means the message would have already been delivered and its properties can no longer be interchangeable.

If that still doesn’t work, instead of "", try making it " " (one space in between the quotation marks) when setting the text.

Sorry, I forgot to respond, but the reason why it didn’t work is because I didn’t use TextChatService correctly, but it works now.