Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Filtering String Async not working? instead saying 2nd argument is missing??

I made a script that prevents scammers from scamming other players, I'm going to add more filter stuff in the table soon.

It's saying that the 2nd argument is missing on the last line aka. :FilterStringAsync()

local txtservice = game:GetService("TextService")

local filterWhiteboard = {"robux.gg", "free robux"}

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg)
		for _, v in ipairs(filterWhiteboard) do
			if string.lower(msg) == v then
				
				txtservice:FilterStringAsync(msg)
			end
		end
	end)
end)

11 comments

0

txtservice:FilterStringAsync(msg, player)?

0

ohh

0

I'll try

0

The problem is your code is seeing if they say "robux.gg" or "free robux" exactly. If they add a capital letter or a period at the end, the code isn't going to work because it isn't exact. Use string.lower or string.upper with string.find to see if there is a message saying "free robux" anywhere in their code. When you call FilterStringAsync, it returns an instance.

0

not working

0

@lorddragonzord so how do i filter the message ??

0

Don't use FilterStringAsync at all, basically. I also wouldn't kick anyone who says "robux.gg" immediately, perhaps give them a warning of some sort so that real players don't get kicked for saying it as a joke, for example.

0

Like I said earlier. Use a combination of string.lower/string.upper and string.find. Look here for more information: https://developer.roblox.com/en-us/api-reference/lua-docs/string

0

i dont want to kick them, but replace the message with hashtags.

0

Doesn't roblox already filter the messages before it gets sent :/

0

The problem with roblox's filtering is that it doesn't filter out robux.gg or free robux at all. Even to those who are less than 13 years of age. Your best bet is to make your own chat gui and use string.gsub to censor out any blacklisted words.

2 answers

FilterStringAsync has 3 parameters, but you only added 1.


  1. StringToFilter
local textService = game:GetService("TextService")

local message = "Hello World!" -- the string to filter

textService:FilterStringAsync(message) 

  1. FromUserId
local textService = game:GetService("TextService")

game.Players.PlayerAdded:Connect(function(player)
    player.Chatted:Connect(function(message)
        textService:FilterStringAsync(message,player.UserId)
    end)
end)

  1. TextContext

(optional)

local textService = game:GetService("TextService")

game.Players.PlayerAdded:Connect(function(player)
    player.Chatted:Connect(function(message)
        textService:FilterStringAsync(message,player.UserId,Enum.TextFilterContext.PublicChat)
    end)
end)

Edited code:

local txtservice = game:GetService("TextService")

local filterWhiteboard = {"robux.gg", "free robux"}

game.Players.PlayerAdded:Connect(function(player)
    player.Chatted:Connect(function(msg)
        for _, v in ipairs(filterWhiteboard) do
            if string.lower(msg) == v then

                txtservice:FilterStringAsync(msg, player.UserId)
            end
        end
    end)
end)

Also, your code is detecting if their chat is only robux.gg or free Robux, so use string.find.

local txtservice = game:GetService("TextService")

local filterWhiteboard = {"robux.gg", "free robux"}

game.Players.PlayerAdded:Connect(function(player)
    player.Chatted:Connect(function(msg)
        for _, v in ipairs(filterWhiteboard) do
           if string.find((string.lower(msg), v) then
                txtservice:FilterStringAsync(msg, player.UserId)
            end
        end
    end)
end)

FilterStringAsync has 3 parameters: stringToFilter: the strings you want to filter.

playerFrom: the player that sent the text.

playerTo: (This one I got from devforum wiki) The intended recipient of the provided text; use the author if the text is persistent.

So basically, you need to enter the player in the playerFrom argument, just like so:

-- filterstringasync is deprecated in local scripts, so we doing it in a server script
local txtservice = game:GetService("TextService")

local filterWhiteboard = {"robux.gg", "free robux"}

game.Players.PlayerAdded:Connect(function(player)
    player.Chatted:Connect(function(msg)
        for _, v in ipairs(filterWhiteboard) do
            if string.lower(msg) == v then

                txtservice:FilterStringAsync(msg,player) -- added the player argument from PlayerAdded
            end
        end
    end)
end)

I hope this answered your question!

This discussion is preserved as it was. New answers, comments, and votes are closed.