Checking is something begins with :

The following code is supposed to check if a message starts with “:” then if it does, delete the message.

local module = require(game.Chat.ChatScript.ChatMain.ChatChannel)

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(speaker, recipient, message)
		if string.sub(message, 1, 1) == ":" then
			module.methods:RemoveMessage(message)
		end
	end)
end)

It currently gives the error

 invalid argument #1 to 'sub' (string expected, got nil) 
2 Likes

Chatted only gives message and the deprecated recipient as the last parameter. Delete speaker and recipient from your function.

1 Like

Nope, still doesn’t work.

This time it gave the error:

attempt to index nil with 'RemoveMessage' 
1 Like

There’s an error with the module, whereas the code above is working fine. I’m assuming you don’t want the message to be delivered, therefore, you could use

Chat:RegisterChatCallback("OnServerReceivingMessage", function(message)
    message.ShouldDeliver = false 
    return message
end)

instead.

2 Likes

In the chat script? or the module script?

Replace with:

			module.methods:RemoveMessage(message)

Tysm!!! :smiley: :smiley:

I found a pretty easy way to do this.

game.Chat:RegisterChatCallback("OnServerReceivingMessage", function(message)
	message.ShouldDeliver = string.sub(message.Message,1,1) ~= prefix
	return message
end)
2 Likes

Someone already said that. Also, I already found a solution…