Help with text filtering

Im trying to make a text filtering module, but everytime it returns my playerID, does anyone know why?

local TextService = game:GetService("TextService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local module = {}

function module:Filter(ogText, playerId)
	local filteredText = ogText
	
	local success, errorMessage = pcall(function()
		filteredText = TextService:FilterStringAsync(ogText, playerId)
		return filteredText
	end)
	
	return filteredText
end

return module
1 Like

Can you show where the module function is being called?

1 Like
local function filterAllResults()
	for i,v in pairs(game.Players:GetChildren()) do
		local PlayerId = game.Players:GetUserIdFromNameAsync(tostring(v))
		
		_G.finishedStuff[v].prompt = textFilter.Public(_G.finishedStuff[v].prompt, PlayerId )
		for ii, vv in pairs(_G.finishedStuff[v].story) do
			vv = textFilter.Public(vv)
		end
	end
end
1 Like

There’s no textFilter:Filter() function there?

1 Like

oh sorry i was editing the code and forgot to change it back to how it was-- the .Public is the :Filter()

Maybe change this to:

local TextService = game:GetService("TextService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local module = {}

function module:Filter(ogText, playerId)
	local filteredText = ogText
	
	local success, result = pcall(function()
		filteredText = TextService:FilterStringAsync(ogText, playerId)
		return filteredText
	end)
	
    if success then
         return result
    else
         return filteredText
    end
end

return module

its still returns my player ID

Maybe because this has no user id??

once again, i was editing the code and forgot to change it back to how it was

1 Like

ok progress! Now its returning an Instance named Instance

1 Like

I think this post explains why it returns an instance

1 Like

it filters everything. I thought it worked because when I tested it was filtered, but because it uses rich text to make it have colors (or I think that’ought to be the reason) it censors everything no matter what

2 Likes

local TextService = game:GetService("TextService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local module = {}

function module:Filter(ogText, Player) -- # Instead of sending Player UserID Send the Player Instance.
	local filteredText = ogText
	
	local success, errorMessage = pcall(function()
		filteredText = TextService:FilterStringForBroadcast(ogText, Player)
		return filteredText
	end)

   if not success then warn("Had issues filtering message. " .. errorMessage) reutrn end
	
	return filteredText
end

return module

Try this, I haven’t had any issues when using FilterStringForBroadcast.