Text filter not working?

local TextService = game:GetService("TextService")

local function GetTextObject(message, fromPlayerId)
	local TextObject
	local Success, Error = pcall(function()
		TextObject = TextService:FilterStringAsync(message, fromPlayerId)
	end)
	
	if Success then
		return TextObject
	else
		print("Error generating TextFilterResult:", Error)
	end
	
	return false
end

local function GetFilteredMessage(textObject)
	local FilteredMessage
	local Success, Error = pcall(function()
		FilteredMessage = textObject:GetNonChatStringForBroadcastAsync()
	end)
	
	if Success then
		return FilteredMessage
	else
		print("Error filtering message:", Error)
	end
	
	return false
end

function IDService.Client:ChangeName(player, newDisplayName)
	self.Server:ChangeDisplayName(player, newDisplayName)
end

--// Change player display name
function IDService:ChangeDisplayName(player, newDisplayName)
	local PlayerData = DataService:Get(player)
	
	local MessageObject = GetTextObject(newDisplayName, player.UserId)
	
	local FilteredName = ""
	FilteredName = GetFilteredMessage(MessageObject)
	print(FilteredName)
	PlayerData.DisplayName = FilteredName
	
	player:SetAttribute("DisplayName", FilteredName)
end

Got code from here Text and Chat Filtering but it ain’t filtering anything :confused:

Players can enter their name, cutting off the name, but you can imagine what the rest of the word is
image

I don’t know what you are trying to do here, can you tell me the following,

  • What are you trying to achieve?
  • What is going wrong?
  • What is the console outputting, any errors/warnings thrown?

Give me this and I will be happy to help you

He’s trying to make chat filter work on his name selection GUI and its not working.

The code i got too from Text and Chat Filtering isn’t working so i instead use HttpService to get all the raw text in GitHub/Etc. to get all the inappropriate/profanity words and ( wait a bit, surely you have to convert it to LUAU table)if the word that the user placed in the texbox was in that raw then we will use string.rep to change all the characters to “#”

i last did this was like January so i don’t use filter function very much on my text box.

Where did you test the code? Filtering doesn’t occur in studio sessions.