How would you check when the player speaks in chat and what the player says?

I’ve been trying to make communication with a phone and textchatservice display bubbles and everything i’ve tried hasn’t worked very well. Using TextChatService OnIncomingMessage fires every message so it’ll send in messages from players not in the call and from the system, ChatService is deprecated so I’d prefer not to use it and Player.Chatted isn’t firing when I call it from a localscript.

If anyone knows how or if you need more info, let me know! This has been racking my brain for ages.

Do you necessarily need the script to be a localscript? Because from my experience player.chatted works fine serverside but doesnt work locally

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(message)
		print(message)
	end)
end)
1 Like

That’s new to me. Did they change how it works?

This would have to be handled on the server and utilizing a special “key” between players A and B.

1 Like

I don’t need it to be as I have two seperate scripts within my phone tool that are local and server side. Though I believe I’ll need to send stuff to a remote event to send messages?

I will check out your code later! Thank you!

Previously I just used a fireserver with who I was sending it to in the parameters. Then an onserverevent or onclient event to check for the event firing.

Player.Chatted only fires on the server. For some strange reason.

Anyway, I’d recommend using TextChatService.MessageReceived. .OnIncomingMessage is only generally for things like chat tags and the such, which need to modify the message. MessageReceived is when the message has been delivered.

it also respects this (but so does OnIncomingMessage), but you can use that to control who gets it.
image

1 Like

Ooo okay! Is there a way with this method to check who sent it? Previously with OnIncomingMessage it sent every message in the server.

1 Like

OnIncomingMessage provided it too - it’s a part of the TextChatMessage!

TextChatService.MessageReceived:Connect(function(msg: TextChatMessage)
    local sender = msg.TextSource and
        msg.TextSource.UserId and --included this cuz idk if that can be nil if sent by the system
        Players:GetPlayerByUserId(message.TextSource.UserId) --do not want this erroring

    if (not sender) then print("System message!") end
    --etc.
end)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.