Chat Filtering is not working on my custom chat gui

So I thought to try to make my own custom chat, and I manage to do that and got it working, but now I’m trying to filter the chat just in case someone says a cuss word but its not working

here’s the server script

local ReplicatedS = game:GetService("ReplicatedStorage")

local ChatMessageRemote = ReplicatedS.Remotes:WaitForChild("ChatMessageRemote")

local Filtered




ChatMessageRemote.OnServerEvent:Connect(function(Player, Text, Thumbnail)
	

	pcall(function()

		Filtered = game:GetService("TextService"):FilterStringAsync(Text, Player.UserId)
		
		Filtered = Filtered:GetNonChatStringForBroadcastAsync()
	end)
	
	if not Filtered then return end
	
	
	ChatMessageRemote:FireAllClients(Player, Text, Thumbnail)
end)

here’s the local script if you need to see it

local Thumbnail = game:GetService("Players"):GetUserThumbnailAsync(
	
	Player.UserId,
	
	Enum.ThumbnailType.HeadShot, 
	
	Enum.ThumbnailSize.Size420x420
)

PlayerImage.Image = Thumbnail




TextBox.FocusLost:Connect(function()
		
	if TextBox.Text ~= "" then	
		
		ChatMessageRemote:FireServer(TextBox.Text, Thumbnail)
		
		TextBox.Text = ""
	end
end)




ChatMessageRemote.OnClientEvent:Connect(function(Player, Text, Thumbnail)
	
	local NewMessage = ChatMessage:Clone()
	NewMessage.PlayerName.Text = tostring(Player)
	NewMessage.TextFrame.TextBox.Text = Text
	NewMessage.PlayerImage.Image = Thumbnail
	NewMessage.Parent = ScrollingFrame
end)

In your server code where you FireAllClients, you input Text variable from the original Server Event Parameters and not the Filtered variable
Also the Filtered Variable should be localized within the Server Event function.

It should look like this

-- < SERVER > --
local ReplicatedS = game:GetService("ReplicatedStorage")
local ChatMessageRemote = ReplicatedS.Remotes:WaitForChild("ChatMessageRemote")

ChatMessageRemote.OnServerEvent:Connect(function(Player, Text, Thumbnail)
	local Filtered

	pcall(function()
		Filtered = game:GetService("TextService"):FilterStringAsync(Text, Player.UserId)
		Filtered = Filtered:GetNonChatStringForBroadcastAsync()
	end)
	
	if not Filtered then return end
	
	ChatMessageRemote:FireAllClients(Player, Filtered, Thumbnail)
end)

ohhhh, woww, thanks it works now

Nice, you should mark my post as the solution.

Have a nice rest of your day.