How to filter a string?

So I wrote a filter function but it doesn’t seem to return a filtered string. “Discord” should be filtered.

local filterResults = {}

local function broadcastPetName(userId)
	local filterResult = filterResults[userId]
	
	if filterResult then
		local filteredString = filterResult:GetNonChatStringForUserAsync(userId)
		filteredString = filteredString or ""

		return filteredString
	end
end

game.Players.PlayerAdded:Connect(function(player)
	local fromUserId = player.UserId

	local success, result = pcall(function()
		return TextService:FilterStringAsync("discord", fromUserId)
	end)

	if success then
		filterResults[fromUserId] = result

		local result = broadcastPetName(fromUserId)
		print(result)
	else
		print("Could not filter pet name")
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	local userId = player.UserId
	filterResults[userId] = nil
end)

image

Studio does not filter text like this when printing. Try it in game instead.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.