Custom Filter doesn't work

Hey there! I’m making an admin panel for my friend’s game and I decided to add a system message command. I decided to add a filter in case someone tries to say something rude.
However, it doesn’t filter. Here’s my current code:

elseif script.Parent.Parent.TextLabel.Text == "System Message" then
		local StarterGui = game:GetService("StarterGui")
		local text = script.Parent.Parent.TextBox.Text
		local textsplit = string.split(text, " ")
		local finaltext = ""
		for i = 1, #textsplit do
			for j = 1, #unallowedwords do
				if textsplit[i] == unallowedwords[j] then
					local badword = unallowedwords[j]
					if #badword == 3 then
						textsplit[i] = "###"
					elseif #badword == 4 then
						textsplit[i] = "####"
					elseif #badword == 5 then
						textsplit[i] = "#####"
					end
				end
			end
			finaltext = finaltext..textsplit[i].." "
		end
		repeat
			wait()
			local Success = pcall(function()
				StarterGui:SetCore("ChatMakeSystemMessage", {
					Text = text;
					Color = Color3.fromRGB(0, 0, 0);
					Font = Enum.Font.Cartoon;
					TextSize = 18
				})
			end)
		until Success
	end

Thanks for stopping by to help!
(I’m not that good at scripting)

Hi, I’m noticing that the way you’re filtering text is by a self-made list. Also the way you’re filtering them is by each word in the string. This has numerous flaws. One being that a player can bypass that filter by saying something like “sdfjskfsbadwordasdksad” because it doesn’t exactly represent a bad word in your list.

I’d personally say your safest option would be to use Roblox’s Text Filtering Service.

If you don’t like that, you could look into string manipulation (string.find and string.replace would seem useful in your case).

Agreed that Text Filtering would be the easiest option overall. Furthermore you’re required to run it through Roblox’s text filter either way. “If a game is reported or automatically detected to not use filtering, that game will be shut down until the developer takes the proper steps to apply filtering.”

Unless you’re wanting to add a custom filter as well (which I personally dont see many use cases for) then that’s your best bet