Plr.Chatted not working in Local Scripts

Hello. For some reason, plr.Chatted isnt working on the client. It works on the server but I am trying to get it to work on the client. I made a new local script and placed it in StarterPlayerScripts but it doesnt print anything.

game.Players.LocalPlayer.Chatted:Connect(function(message)
	print(message)
end)

I dont know what the problem is, im pretty sure it is supposed to work on the client

1 Like

Hello. This is pretty common to people who are new to the .Chatted event.

The problem is simply that you cannot use .Chatted on a localscript.

1 Like

As @GIassWindows has mentioned, the .Chatted event does not work in a LocalScript, only in a server script. Assuming you don’t have the legacy chat enabled, there is a simple workaround to the problem at hand. I will share some sample code if it helps, but the way to do it is to get the TextChatService service, then use the .SendingMessage event to tell when the player is sending a message. There, you can grab the chat message, and do whatever you want with it. (NOTE: This only works in a LocalScript, so do you .Chatted in a server script.)

local TextChatService = game:GetService("TextChatService")

TextChatService.SendingMessage:Connect(function(ChatMessage)
	print(ChatMessage.Text) -- prints whatever the player said (as ChatMessage is NOT the text of the chat messge)
end)
3 Likes

Ohh okay. Thanks. I have a few questions though

  1. What is Legacy chat?

  2. Im guessing TextChatService.SendingMessage will only work for messages sent by the local player?

1 Like

Here’s some answers to your question!

  1. Basically, Roblox revamped the legacy chat, and made it even better, with the benefit of the same features. Though they couldn’t remove legacy chat; it could break games that still uses it, or the other people who still want to use it. Hopefully that was a clear enough explanation for you, didn’t want to make it too long!

  2. Yes, you are correct. Infact, the description for it says it can only be called on the client: “Fires when TextChannel:SendAsync() is called by the sending client.” (By the way, TextChannel:SendAsync() does NOT have to be sent in a script for it to register, sending a message on the client already fires that (just to clear up any confusion).

2 Likes

Hi, sorry for the late reply. It works perfectly. I am using the TextChatService Custom command which I never knew about before, so thank you for telling me about TextChatService :pray:

1 Like

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