I migrated to the new TextChatService and I’m confused with all those MessageReceived, SendingMessage, OnIncomingMessage…
I’m trying to connect a function to the event of sending a chat message by the player.
Player.Chatted does not work in local scripts when the new chat is enabled (why, btw?). The message should be unfiltered (all the things I listed above return filtered message, I think), I’m planning to filter it later. It’s better for me to do it in a localscript, but both are fine.
My question is how can I get the contents of player’s message? Which event should I choose?
Now anything received from the client will be filtered so I suggest using player.Chatted on the server, filter according to your needs and send it to the client. For the other methods:
- OnIncomingMessage: This connection fires whenever the cahnnel (or textchatservice in general) is about to receive a message, this is effective and is meant to be used before the message is displayed in chat.
- MessageReceived: As stated by the document, this only fires when specific functions like :DisplaySystemMessage() or :SendAsync() are fired.
- SendingMessage: This event fires whenever :SendAsync() is called.
If you certainly want to do it on the client (even though it can be exploited) then use OnIncomingMessage.