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

Add a filter that checks for a certain word / phrase in a username?

I have a blacklist that bans players if they're blacklisted in the script but I want to add a filter that bans players with a certain word / phrase in their username. How do I do this? My script is below

local blacklist = {
    ["BlacklistedPlayer"] = true
}

game.Players.PlayerAdded:connect(function(p)
    if blacklist[p.Name] then
        p:Kick("Ban Reason")
    end
end)

if player is in local blacklist table then kick them for reason. How do I add a filter to this? Note that I want both the blacklist and filter to be in, not just replaced with a filter

2 answers

✓ Accepted answer

Improvements

Use :GetService() to retrieve the Players service

Explanation

You can use string.match() to make sure part of a player's name matches a word in your second table (returns nil if there is no match)

Revised Server Script

local blacklist = {
	["BlacklistedPlayer"] = true
}
local phraselist = {"dead", "kill"}

game:GetService("Players").PlayerAdded:Connect(function(p)
	if blacklist[p.Name] then
		p:Kick("Ban Reason")
	end

	for _, word in pairs(phraselist) do
		if string.match(string.lower(p.Name), word, 1) then
			p:Kick("Username Blocked")
		end
	end
end)

I also use string.lower() on the player's Name to make sure that the word you place in the table is matched regardless of capitalization.

The script above censors any username with the word "dead" or "kill" in it.

1 comment

1

Thank you, this worked! It's also quite easy to add a phrase blacklist here

This is quite a hard question to answer. My answer might not work but here is my go at it.

In this script I'm going to be banning them if they have the word "cow" in their name.

local blacklist = {
    ["BlacklistedPlayer"] = true
}

game.Players.PlayerAdded:connect(function(p)
	local nameTable = p.Name:Split("")
	for i,v in pairs(nameTable) do
		if v == "c" then
			if nameTable[i + 1] == "o" then
				if nameTable[i + 2] == "w" then
					table.insert(blacklist, p.Name)
				end
			end
		end
	end
    if blacklist[p.Name] then
        p:Kick("Ban Reason")
    end
end)

I'm really really sorry if this didn't work. I hope it did but if it didn't make sure to tell me the problem and I will try my best to help you.

Thank you.

2 comments

0

I don't think it worked, I tested it by blacklisting usernames with "laz", I however was not banned

0

Sorry ;-;

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