I need HELP with this script

local TextChatService = game:GetService("TextChatService")
local rbxGeneralChannel = TextChatService:WaitForChild("TextChannels"):WaitForChild("RBXGeneral")

local CENSOR_WORDS = {
	"test","notallowed","LOL"
}

--//The function that includes various options/possible ways to writing the bad words
local function generateVariations(word)
	local variations = {}

	
	local function helper(current, index)
		if index > #word then
			table.insert(variations, current)
			return
		end

		-- Include the current character without space
		helper(current .. word:sub(index, index), index + 1)

		-- Include the current character with space (if not the last character)
		if index < #word then
			helper(current .. word:sub(index, index) .. " ", index + 1)
		end
	end

	helper("", 1)

	return variations
end

--//The function that handles the filter/replacing the bad words with other characters
local function doFilter(messageObject)
	local getOriginalMessage = messageObject.Text
	--print("Original Message: " .. getOriginalMessage)

	for _, word in pairs(CENSOR_WORDS) do
		local variations = generateVariations(word)

		for _, variation in ipairs(variations) do
			local pattern = variation:gsub("(%a)", function(c) return "[" .. c:lower() .. c:upper() .. "]" end)


			if getOriginalMessage:match(pattern) then

				messageObject.Text = getOriginalMessage:gsub(pattern, "####")
			end
		end
	end
end




--//When we recieve a message 
TextChatService.OnIncomingMessage = function(textChatMessage)
	local textChatMsgProperties = Instance.new("TextChatMessageProperties")
	print(textChatMessage.Text)
	
	 doFilter(textChatMessage)

	
	return textChatMsgProperties
end

do you guys think it’s GOOD or bad [using textService filter]?

I’m probably missing something but are you trying to make your own text filter?

Just so you’re aware, roblox has a built in filter - A Guide to Filtering Text which you should use over your own implementation

2 Likes

no its just a script that REPLACES certain words with other characters yk
i need to KNOW if it’s a good script and if it fits the new terms \ apis of TEXTservice as has been announced

Its not my own filter
it just hashtags specific words which the built in filter does not