Filtering Doesnt Work

this is a quick post because i have to go to sleep soon, basically, i got a code that basically is for like an interaction between my custom npc and the player, the npc asks for a name, the user says it in the chat, and the code saves the username, and the npc remembers the player by his name, the problem is that i can input some really innapropriate stuff in it and it wont be filtered, i tried messin around with the script, and either everything i say is “fine” or everything i say is “filtered” please help.

local DataStoreService = game:GetService("DataStoreService")
local TextService = game:GetService("TextService")
local playerNameStore = DataStoreService:GetDataStore("PlayerNameStore")

local gangsterChicagoPhrases = {
	"Wassup cuh, my name's ",
	"Yo, name's . What's good?",
	"They call me 'round here, ",
	"Ayy, I'm , nice to meet ya, ",
	"Yo, I'm . How ya doin', ",
	"Wassup, I'm . Who you, ",
	"Hey there, name's , fam, ",
	"Yo, it's . What's poppin', ",
	"Ayo, I'm . What's crackin', ",
	"Wassup, I'm . Stay cool, ",
}

local function savePlayerName(player, playerName)
	local userId = player.UserId
	local success, err = pcall(function()
		playerNameStore:SetAsync(userId, playerName)
	end)

	if success then
		print("Name saved successfully for player:", playerName)
	else
		warn("Error saving name for player:", err)
	end
end

local function checkDuplicateName(playerName)
	local success, allKeys = pcall(function()
		return playerNameStore:ListKeysAsync()
	end)

	if success then
		while true do
			for _, key in pairs(allKeys:GetCurrentPage()) do
				local success, existingName = pcall(function()
					return playerNameStore:GetAsync(key)
				end)
				if success and existingName == playerName then
					return true
				end
			end

			if allKeys.IsFinished then
				break
			else
				allKeys:AdvanceToNextPageAsync()
			end
		end
	else
		warn("Failed to list keys:", allKeys)
	end

	return false
end

local function isNameCensored(name, userId)
	local success, result = pcall(function()
		return TextService:FilterStringAsync(name, userId)
	end)

	if success then
		local filteredText = result:GetNonChatStringForBroadcastAsync()
		if filteredText == name then
			print("Filtered word!")
			return true
		else
			print("Word is fine!")
			return false
		end
	else
		warn("Failed to filter name:", result)
		-- Treat as censored if the filtering fails, to be safe
		return true
	end
end


local function askForName(player)
	local chatConnection
	local responded = false

	local function stopListening()
		if chatConnection then
			chatConnection:Disconnect()
			chatConnection = nil
		end
		if not responded then
			game:GetService("Chat"):Chat(script.Parent, "Mane stop wastin my time", Enum.ChatColor.White)
		end
	end

	game:GetService("Chat"):Chat(script.Parent, "Yo wassup, I didn't see you around here, what's yo name?", Enum.ChatColor.White)

	chatConnection = player.Chatted:Connect(function(message)
		responded = true
		if isNameCensored(message, player.UserId) then
			game:GetService("Chat"):Chat(script.Parent, "Mane, stop makin' up names!", Enum.ChatColor.White)
		elseif checkDuplicateName(message) then
			game:GetService("Chat"):Chat(script.Parent, "Oh! I think I already heard a name like that, anyways nice to meet you!", Enum.ChatColor.White)
		else
			savePlayerName(player, message)
			local phrase = gangsterChicagoPhrases[math.random(#gangsterChicagoPhrases)] .. message
			game:GetService("Chat"):Chat(script.Parent, phrase, Enum.ChatColor.White)
		end
		stopListening()
	end)


	delay(10, stopListening)
	print('idk')
end

local function greetPlayer(player)
	local userId = player.UserId
	local playerName = playerNameStore:GetAsync(userId)

	if playerName then
		game:GetService("Chat"):Chat(script.Parent, "Welcome back, " .. playerName .. "!", Enum.ChatColor.White)
	else
		askForName(player)
	end
end

local npcPart = script.Parent  -- Assuming the script is inside the NPC part
local otherPart = script.Parent.Parent.Interact
local detectedPlayers = {}  -- Table to keep track of detected players

local function detectPlayerInFront()
	while true do
		local direction = npcPart.CFrame.LookVector
		local rayOrigin = npcPart.Position
		local rayLength = 10  -- Adjust as needed

		-- Create a visible line to show the detection area
		local linePart = Instance.new("Part")
		linePart.Anchored = true
		linePart.Transparency = 1
		linePart.CanCollide = false
		linePart.Size = Vector3.new(0.2, 0.2, rayLength)
		linePart.CFrame = CFrame.new(rayOrigin + direction * rayLength / 2, rayOrigin + direction * rayLength)
		linePart.BrickColor = BrickColor.new("Bright red")
		linePart.Parent = workspace

		local raycastParams = RaycastParams.new()
		raycastParams.FilterType = Enum.RaycastFilterType.Exclude
		raycastParams.FilterDescendantsInstances = {npcPart, linePart, otherPart}

		local result = workspace:Raycast(rayOrigin, direction * rayLength, raycastParams)

		if result then
			local player = game.Players:GetPlayerFromCharacter(result.Instance.Parent)
			if player and not detectedPlayers[player.UserId] then
				greetPlayer(player)
				detectedPlayers[player.UserId] = true
			end
		else
			-- Reset detectedPlayers if no player is detected
			for userId, _ in pairs(detectedPlayers) do
				detectedPlayers[userId] = nil
			end
		end

		wait(1)  -- Adjust the wait time as needed
	end
end

spawn(detectPlayerInFront)
1 Like
if filteredText == name then
	print("Filtered word!")
	return true
else
	print("Word is fine!")
	return false
end

Isn’t this supposed to be reversed? Like filteredText ~= name

tried that, didnt work. im pretty sure, but ill double check

tried it, and even after saying a slur it says “Word is fine”

I’m pretty sure that alongside what I said, filtering text is disabled in Studio and you can say profanities in chat. I don’t know exactly if this affects FilterService

Filtration services are unavailable in Roblox Studio. You will only see results in-game

no, no, no, i tried it in roblox, and it also doesnt work

okay, weird thing, i tried the same script twice, the first try it didnt work, but now the filtering is completely fine, so uhhh, i think its something with roblox studio, thanks for helping.

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