I’m currently attempting to learn the new chat system, and I want to use OnIncomingMessage as it’s much more reliable for certain situations compared to MessageReceived.
What do you mean by “two callbacks”? OnIncomingMessage
is a property, not a connection of some kind, which means it can only hold one value at a time. Therefore, the latest callback you assign will be the one it uses.
That’s happening because the callback is triggered when the TextChatMessage’s Status is either Sending
or Success
, so you can use an if statement to check whether the message’s status is the relevant one for your needs
Example code:
local TextChatService = game:GetService("TextChatService")
local function onIncomingMessage(message: TextChatMessage)
if message.Status == Enum.TextChatMessageStatus.Success then
-- Run your code inside of this if statement
end
end
TextChatService.OnIncomingMessage = onIncomingMessage
Two call backs meaning, when a message is sent with OnIncomingMessage… fires twice when binded on the client. This causes issues when you want to fire an Event as the event will fire twice. I was originally doing this to create a system where I could turn the chat censor off for certain instances.
Client Functionality: When bound to the client sending a message, this callback is run twice; first when the message is initially sent and received locally, and again when the client receives the result of the filtered message from the server