How can I get the player chat content in a script

Hey !
I’m trying to make an intercom, so I need to get what the player said in a specific zone.
Scripting itself shouldn’t be a problem, but I just want to know how I can get player chat content in a script
Like if he say “Someone is sus”, the server will say “Someone is sus”

2 Likes
function ListenForChat(Player)
       Player.Chatted:Connect(function(Message)
             local Filtered = game:GetService("TextService"):FilterStringAsync(Message, Player.UserId)
             -- Do stuff with Player and Filtered, not Message
       end)
end

This is only possible on the server due to filter text, get a remote function if you want to do this on the client

1 Like

What do you mean by – Do stuff with Player and Filtered, not Message

1 Like

Message is the unfiltered message with any swear words. Filtered is the filtered version.
You can use the player’s message and manipulate it in any way you want

1 Like

Ohhhh ok
Thanks for your help mate !

1 Like

Ok so here is the script that I created, but server doesn’t say anything :

local zone = game.Workspace.Detection
function ListenForChat(Player)
	Player.Chatted:Connect(function(Message)
		local Filtered = game:GetService("TextService"):FilterStringAsync(Message, Player.UserId)
		local function chat(message)
			game.StarterGui:SetCore("ChatMakeSystemMessage", { Text = message, Colour = Color3.fromRGB(16, 110, 139), Font = Enum.Font.SourceSans})
		end
		chat(Filtered)
	end)
end

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg)
		if zone.Touched then
			ListenForChat()
		end
	end)
end)

ListemForChat automatically listens for the chat. No need for player.Chatted.
Just call ListenForChat(Player)
Also, for ChatMakeSystemMessage, you have to use a remote event and fire all clients to make the system message on the client