How to detect team and whisper chats on the client

I want to detect when the client receives a team or whisper team from any other player.

I’ve tried the following code but it doesn’t print anything when a player speaks.

-- // Services
local PlayerService = game:GetService("Players")

-- // Functions
PlayerService.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(message)
		print(message)
	end)
end)

I tried the same script on the server, and it works but you can’t tell which chats are team chats or whispers. You might think “you can just find what ones have /t or /w” but no, that’s only for the first initial message.

The only other way to detect is via ChatService but it doesn’t seem to be able to detect whispers and team chats and only works in the All channel.

I’m currently at a loss and would appreciate any help and/or input.

Why do you want to detect when a player whispers?

And i dont think this is possible

I was able to achieve what you want by detecting when a child is added to the chat scroller (the frame that holds all chat messages).

Below is the code that I used to achieve it!

local Scroller = game.Players.LocalPlayer.PlayerGui:WaitForChild("Chat").Frame.ChatChannelParentFrame.Frame_MessageLogDisplay.Scroller
Scroller.ChildAdded:Connect(function(child)
	local TextLabel = child.TextLabel
	local Type = ""
	if #TextLabel:GetChildren() == 0 then
		Type = "System"
	elseif #TextLabel:GetChildren() == 1 then
		Type = "Normal"
	else
		local IsTeam = false
		for _, button in ipairs(TextLabel:GetChildren()) do
			if button.Text == "{Team}" then
				IsTeam = true
			end
		end
		
		if IsTeam then
			Type = "Team"
		else
			Type = "Whisper"
		end
	end
	print(Type)
end)

Type will either be “System”, “Normal”, “Team”, or “Whisper”

1 Like

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