Player.Chatted broken on LocalScripts

Are we talking about the same Player.Chatted? It used to be able to capture messages from other players, not just the LocalPlayer.

This type of local script used to work for all Players, up until yesterday, where now you can only catch .Chatted events from the LocalPlayer.

Something like this would have worked in a LocalScript:

local function playerAdded(player)
	player.Chatted:Connect(function(message)
		print(player.Name .. " chatted: " .. message)
	end)
end)

for i, player in pairs(game.Players:GetPlayers()) do playerAdded(player) end
game.Players.PlayerAdded:Connect(playerAdded)
6 Likes

Can confirm, this is no longer working as intended.
Reproduction:

local Game = game
local Players = Game:GetService("Players")

local function OnPlayerAdded(Player)
	local function OnPlayerChatted(Message)
		print(Message)
	end
	
	Player.Chatted:Connect(OnPlayerChatted)
end

Players.PlayerAdded:Connect(OnPlayerAdded)
for _, Player in ipairs(Players:GetPlayers()) do
	OnPlayerAdded(Player)
end
6 Likes

For those that are still looking for a workaround for this, an easy way to log every chat message on the client from a player is this:

local chatEvents = game:GetService("ReplicatedStorage"):WaitForChild("DefaultChatSystemChatEvents")
local messageDoneFiltering = chatEvents:WaitForChild("OnMessageDoneFiltering")

messageDoneFiltering.OnClientEvent:Connect(function(message)
	local player = players:FindFirstChild(message.FromSpeaker)
	local message = message.Message or ""

	if player then
		print(player.Name .. ": " .. message)
	end
end)
2 Likes

Why use a PlayerAdded event when you can just get the player with game:GetService('Players').LocalPlayer?

Also relevant information about the PlayerAdded event in localscripts:

  • This event does not work as expected in solo mode, because the player is created before scripts that connect to PlayerAdded run. To handle this case, as well as cases in which the script is added into the game after a player enters, create an OnPlayerAdded function that you can call to handle a player’s entrance.

Here is how to fix it simply.

Before I move on, I just want to clear everything out:

  • Local Scripts are not broken.
  • The Framework could be done on the Local Script.

Now here’s how you do this:

Firstly, you want to make a Remote Event under your Local Script. You want to make a ServerScript in ServerScriptService and type this:

wait(.2);

function Framework(Msg, Plr)
	for i,plrs in pairs(game.Players:GetChildren()) do
		plrs.StarterPlayer.StarterPlayerScripts.Chat.Chatted:FireAllClients(Msg, Plr) -- Your RemoteEvent
	end
end

while wait() do
	for i,plrs in pairs(game.Players:GetChildren()) do
		plrs.Chatted:Connect(function(Msg, Plr)
			Framework(Msg, Plr)
		end)
	end
end

What this will do, is it will detect when a single player has chatted, and when they have chatted, it will fire your remote event, but we now have to detect when that is fired, So in your local script, clear everything, and write this:

wait(.2);

script.Chatted.OnClientEvent:Connect(function(Msg, Plr)
	print(Plr.Name .. ': ' .. Msg)
end)

It will detect whenever the player has chatted, then it will get there Message and Player, then it will print as an example: “Player1: Hi”

You have to utilize the script to your event parent and script parent. Just make sure it’s right, because if it’s not the script wont work and it’s not my fault.

Thanks however the Chatted function on local scripts was shortly brought back after this post.

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