Can you help me fix my Chat Filter System

Hello.

I am trying to make my own chat system.

I want to know is this right:

function Filter(Message, Player)
	local Text = false
	Text = ChatService:FilterStringForBroadcast(Message, Player)
	if string.find(Text, "#") then 
		print("Input from "..Player.Name.." was filtered.")
	else 
		print("All clean! We can ship the text chain (aka string).")
	end
	print(Text)
	return Text
end

I am trying to Filter the message.

Can you tell me if this works. Thanks :slight_smile:

Test it yourself? lorem ipsum

1 Like

It dose not seem to work, can you help me fix it.

I have not looked at your code yet

Are you testing in studio? You must test chat services in an actual play session and not from studio play.

1 Like

I went into the game and typed lorem ipsum into the chat beucase @PMGDesigns said it would he blocked. And it did not work.

I only sent that in spoilers so my message was above the minimum, try things you know will be filtered.

Hey, Instead of finding “#”. try comparing the original, and the filtered string, because the player can include # in their text.

So, just do if Text ~= Message instead of string.find(Text,"#")

Well, Thats just to debug, But mainly if I see the text filterd

It works think you guys, Have a good day!

Someone can fake hashtags. Instead, use string.gsub to find any character that’s not a hashtag. If it comes out as a hashtag, then you can say that it was filtered. Example:

function pack(...)
	return {...}
end
function Filter(Message, Player)
	local Text = false
	local Character_Indexes = {}
	string.gsub(Message,".", function(char) 
		if char ~= "#" then
			table.insert(Character_Indexes,pack(Message.find(char))[1])
		end
	end)
	Text = ChatService:FilterStringForBroadcast(Message, Player)
	
	local NewChars = {}
	
	for x,v in Character_Indexes do
		NewChars[x] = Text:sub(v,v)
	end
	
	if table.find(NewChars,"#") then 
		print("Input from "..Player.Name.." was filtered.")
	else 
		print("All clean! We can ship the text chain (aka string).")
	end
	print(Text)
	return Text
end

This can probably be optimized easily but too lazy right now :sweat_smile:

ITS FOR DEBUGING, NOT TO KEEP!!!

I am sorry for the miss under standing

Oh! It’s okay. I thought you wanted something like Roblox’s DMs where if just one letter gets tagged the message doesn’t get sent.

1 Like

I going to make it like if there to many tags, the message will be shown as “[Content Deleted]”. But if I add a DM think, that would work, thanks for the idea.