Help with chat system filtering

I’ve tried my best to make the chat filter work but I just can’t seem to get it working. It would be awesome if you guys could either help by doing it for me or giving me tips. Here’s the model with everything in it. Chat Help.rbxm (14.8 KB)

What exactly you’re trying to achieve with Chat filtering?

Make is so like curse words n stuff get filtered out like normal roblox chat

So you’re making a custom chat?

Yes. The chat part works it’s just the filtering that doesent.

Well, I don’t know what I can do with it because I’m not good at making custom chats, why not take a look at roblox’s scripts to see how it works for them?

I have looked at the roblox chat and sadly I can’t find a difference

Read up on TextService:FilterStringAsync()

I have and still can’t understand it. If you look into the scripts you can see it’s fairly close to the api reference.

If you’re only testing in Studio then it won’t work. I know it’s risky but you have to test it in a live game if you’re otherwise unable to find the issue.

Edit: Ok I probably could’ve explained this better, but ANY text filtering will not work in Studio. Even the chat.

but in your case you would use :GetChatForUserAsync(receivingplayer.UserId)

You can just say a few filtered non-swearwords like example.com in the live game

That’s a good idea. I probably should’ve thought of that yesterday when I was testing some filter related stuff.

This article on the developer hub explains this pretty well.

There is a couple of things you should also know when filtering text.

  • It will not work in studio.
  • Filtering may occasionally error and you should wrap the function in pcall.
  • Text filtering only works on the server.

Try this function. This will return a string that is appropriate for all users.

local TextService = game:GetService("TextService")

local function filterText(fromUserId, text)
	local textFilterResult = ""
	local success, errorMessage = pcall(function()
		textFilterResult = TextService:FilterStringAsync(text, fromUserId)
	end)
	if not success then
		warn(errorMessage)
		return "Failed to filter string..."
	else
		return textFilterResult:GetNonChatStringForBroadcastAsync()
	end
end

You could call the function like this:

filterText(game.Players.Enomphia.UserId, "discord")

This would then return “#######” due to discord being censored.

Update: When trying in-game it doesn’t work at all with any errors.

I have an exact version in my current script. If you look at it it’s just about the same.

Are you testing it in studio or an actual game server?

In-studio it works without filtering, in-game it doesn’t work regardless & it has no errors.