Check if Player.Chatted from LocalScript

Hello,

I’m trying to create a LocalScript that checks if someone in the server sends a chat message in the game. This is not possible with game.Players:PlayerAdded, so is there any other method to check if a message is sent in the chat.

(P.S: I’m not trying to use any RemoteEvents or RemoteFunctions)

Thanks.

Why is it not possible with Players.PlayerAdded?

When the player joins there are already players in the game.

You can just loop through all of the current players.

game.Players.PlayerAdded:Connect(function(player)
       --code here
      print(player.Name)
end)

wait(1)
for i, player in pairs(game.Players:GetChildren()) do
     --code here
      print(player.Name)
end

It’s not exacly what I’m trying to achieve, what I’m trying to do is when anyone in the game chats a function gets activated. I’m not sure if it’s possible though…

It is, try this:


local function ONChat()
       print("Player Chatted")
end

game.Players.PlayerAdded:Connect(function(player)
       player.Chatted:Connect(OnChat)
      print(player.Name)
end)

wait(1)
for i, player in pairs(game.Players:GetChildren()) do
     player.Chatted:Connect(OnChat)
      print(player.Name)
end
3 Likes

Can’t you just use local player so like:

local player = game.Players.LocalPlayer

player.Chatted:Connect(function(msg)
--do something
end)

That’s not what I’m trying to do here, I’m trying to make it so that if anyone in the server sends a chat, not just the LocalPlayer.

My code above should work, whenever anyone chats it fires that function. Just put your code inside the function at the top.

It’s a local script, so every client will have it. So that function will run when anyone talks.