The chatted event of LocalPlayer is not binding to the function on Client

Here’s the simple test script I made to test my fps system:

local FPS = require(script.Parent.Classes.FirstPersonEngine.FirstPersonEngine)

local fps = FPS.new()

wait(10)
print("hi")
game.Players.LocalPlayer.Chatted:Connect(function(msg:string)
	print(msg)
	if(msg == "fps enable") then
		fps:EnterFirstPerson()
	elseif(msg == "fps disable") then
		fps:LeaveFirstPerson()
	end
end)

The problem with this script is that even after debugging, It prints “hi” after a wait of 10 seconds, and after that if I type and send something in the chat, it ain’t even printing the message I typed, this should happen as this line print(msg) does it.

I think the problem is that the function I provided to the Connect function, it ain’t binding it. Why?

1 Like

after a quick test, it seems that .Chatted doesn’t work on the client at all.
I believe the solution would be to use TextChatService, like so:

local TCS = game:GetService("TextChatService")
local Player = game:GetService("Players").LocalPlayer

TCS.MessageReceived:Connect(function(Msg: TextChatMessage)
	if (Msg.TextSource) and (Msg.TextSource.Name == Player.Name) then
		print(Msg.Text) -- this is our message!
	end
end)
2 Likes

The docs don’t provide this info or is it a bug? So is the TextChatService for clients, also that event works on the server. Maybe it is server-only?

1 Like

It’s probably server-only and just isn’t well documented as so.

1 Like

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