How do you delete a chat message?

I am working on custom admin commands, and I am trying to make the warn command which makes your message appear in bold red text. I already made the bold red text by creating a new chat message but when I try to :Destroy() on the chat message, it does not destroy the original message. How do I remove the original chat message?

5 Likes

Are you using a completely custom chat system, a plugin for Roblox’s chat system, or an external script that interfaces with the chat system? If you are using a chat module you can do this by setting the message color to red whenever a player chats (and is using warn command) using ChatService. RegisterFilterMessageFunction.

If I remember correctly you cannot destroy a chat message using an external script, the only way you can do this is a chat module.

1 Like

You could make it a bindablefunction so it can be called from a external script :thinking:

3 Likes

True true but still requires you to modify the chat :thinking:

1 Like

So that means there’s no way to delete a chat message without modifying it :thinking:

2 Likes

Yes, since unless you modify it, the chat GUI is parented to game.CoreGui.

3 Likes

Why would you use a BindableFunction? As far as I know, there is no reason for the chat system to send anything back to the script upon deleting a message.

@Monsieur_Robert

Nope, it’s actually parented to PlayerGuis (created by a ModuleScript). Chat system is fully ported to Lua.

1 Like

Ups, i did a mistake there, didn’t notice i said “function” instead of “event”

2 Likes

When a message is created it isnt stored somewhere magical in the roblox universe, its actually ‘hidden’ right under your nose in the playergui : D, I forget the exact reference but look into the chat guis until you find the text label representing your message then just destroy that : D

2 Likes

I think you’ll want to prevent the chat message from being sent in the first place instead of figuring out how to delete it. For this, you can bring out a bit of the Lua Chat System repository to Studio and add to it so it fits your admin commands. The rest of the scripts will automatically insert themselves.

In the Chat service, insert the following:

Folder ClientChatModules
    Folder CommandModules
        BoolValue InsertDefaultModules <true>

Once this is done, insert a ModuleScript, your choice of name. The content of the ModuleScript should essentially flow like this:

local util = require(script.Parent:WaitForChild("Util"))
 
function ProcessMessage(message, ChatWindow, ChatSettings)
	
end
 
return {
	[util.KEY_COMMAND_PROCESSOR_TYPE] = util.COMPLETED_MESSAGE_PROCESSOR,
	[util.KEY_PROCESSOR_FUNCTION] = ProcessMessage
}

You can read up more on that here under Command Modules:
https://developer.roblox.com/en-us/articles/Lua-Chat-System

18 Likes

The message doesn’t show up, but the admin commands that I’m using still processes it. How can I make it so that the admin script doesn’t process the message?

function ProcessMessage(message, ChatWindow, ChatSettings)
	if message == ":kill all" then
        return true --don't let the admin commands execute it!
    else
        return false
    end
end
1 Like

That you will have to edit the admin script itself…

1 Like

this may be easier. follow what is in this topic.

1 Like

The post you’re replying to was made in 2019 and wasn’t exactly proper to begin with. This was intended to be a server command module but I think I confused the two because both the client and server have command modules that they can run on chats.

The canonical way to stop a chat from processing is registering a server-side command module that returns true to prevent the message from being processed further. Command modules are the first processes ran on a chat so if you want to stop it preemptively. ShouldDeliver is also a viable solution but since it’s not documented it can be difficult to actually find.

I prefer to use command modules not only because they’re canonical but because they’re a good fit with most structures. If you fork the folder without the default modules included you can retain a module-based format. Additionally if you have some use case where it’s useful to hook in and out a function you can do so easily with the API because it also supports unregistry.

RegisterChatCallback is a little more rigid. You can’t unregister a callback once it’s been invoked and in my honest opinion it’s less clean when you’re making chat command systems. Depends on how you handle it but chat commands tend to make it easy, idiomatic and consistent. All default chat commands are already implemented as command modules after all.

Easier doesn’t necessarily mean better, but ShouldDeliver is also another way to stop a chat from processing, yeah.

1 Like