Filtering text without a player

I want to know how I can filter text without needing a player. All of the functions I’ve seen require a sender player but in my case I have no sender player or at least the sender player isn’t a valid option for filtering. If anyone has a solution please let me know.

2 Likes

Not sure if this breaks any rules, but you could put a 1 in the field where it asks for a UserId.

I’ll try it but I think it only works if the target userid is in the game

Is something like this what you’re looking for?

1 Like

This is not what I’m looking for. I’m looking for a way to filter text without needing a player/ PlayerId

I don’t fully understand your purpose. Are you doing a search filter or for a UI??

It’s to keep a filtered message throughout different servers. For example a player creates some text in one server and for the sake of simplicity I’ve chosen not to rewrite the function that contains the filtering as that would be too time consuming and difficult to update. So whether or not the text has been filtered already when I run the function through messaging service the userID can no longer be used as the player is not in every server.

I still don’t understand the purpose of this.
The reason the functions require a player argument is because the age of the player (IRL) affects how the text is filtered.


userID can no longer be used as the player is not in every server.

Then, before sending it into the message to other servers, why don’t you use the userID when they are already in the server?

The problem is in order to do that I’ll have to write a new function to perform the same task. As without messaging service.

This shouldn’t be a problem when I’m trying to use :FilterStringForBroadcastAsync or whatever the function is as it has a stricter filter then the default one as it accounts for all ages.

try this code from HERE

local TextService = game:GetService("TextService")
local filteredText = ""
local success, errorMessage = pcall(function()
	filteredTextResult = TextService:FilterStringAsync(text, fromPlayerId)
end)
if not success then
	warn("Error filtering text:", text, ":", errorMessage)
	-- Put code here to handle filter failure
end

text is obviously the text to filter, while fromPlayerId, is the userID of the person who sent the message initially. The resultant text should be what is broadcasted

Literally could read the title…

1 Like

Did you try it?

Nevermind… Found some ways and uses. Check this out:

What are you trying to do with that?

Got it, 2 minutes of research showed me that you can use something called External Sources. It gets a random player for you to filter text from. As you can guess, you will never be able to tell if the filtered text will be from an over 13 or under 13 account before filtering.

Unfortunately this still requires the player,

    local TextService = game:GetService("TextService")
    local ReplicatedStorage = game:GetService("ReplicatedStorage")
    local HttpService = game:GetService("HttpService")
     
    local sendRandomName = ReplicatedStorage.SendRandomName
    local randomNameWebsiteAddress = "http://www.roblox.com/randomname"
    local nameTable = nil
     
    local function initializeNameTable()
    	local nameTableJSON = nil
    	local success, message = pcall(function()
    		nameTableJSON = HttpService:GetAsync(randomNameWebsiteAddress)
    	end)
    	if success then
    		nameTable = HttpService:JSONDecode(nameTableJSON)
    		print("The nameTable is:", nameTable)
    	end
    end
     
    local function onPlayerJoin(player)
    	if nameTable then
    		local randomName = ""
    		local filteredName = ""
    		local filteredNameObject
    		repeat
    			randomName = nameTable[math.random(#nameTable)]
    			local success, errorMessage = pcall(function()
    				filteredNameObject = TextService:FilterStringAsync(randomName, player.UserId)
    			end)
    			if success then
    				print("Success creating filtered object")
    			elseif errorMessage then
    				print("Error creating filtered object")
    			end
    			local success, errorMessage = pcall(function()
    				filteredName = filteredNameObject.GetNonChatStringForUserAsync(player.UserId)
    			end)
    			if success then
    				print("Success creating filtered name")
    			elseif errorMessage then
    				print("Error creating filtered name")
    			end
    		until randomName == filteredName
    		sendRandomName:FireClient(sendRandomName)
    	end
    end
     
    initializeNameTable()
    game.Players.PlayerAdded:Connect(onPlayerJoin)

It’s no big deal though. I’ve just modified the code I already have in my function to store the original filtered message and send it out through messaging service.

1 Like

Yeah as expected it didn’t work, I just gave up and completely redid the function so it would work with messaging service properly.