Ban player if they say word or sentence

Just tried it out and it works like a charm.
Message

1 Like

If you have already lost players on your game, then why not hire a good scripter for your game today itself? And along with it, also make some basic securing scripts. Things like checking the player account age may help, although they can be disadvantages for new players.

But you can search around the devforum for how to store bans in a datastore, so not just kicking but also store them so they aren’t able to join again.


Account Age

I have tried account player age but after I used an admin to info players in game, they have ages 100+ so I cant do an awful lot with the age but thanks for the suggestion.

There are modules around the forum that may help you ban players easily, if you aren’t able to create one yourself (or till your scripter is available).

If you go to this post on the forum, it’s a pretty simple setup and should resolve your issue. You’ll put the “AntibotSettings” folder in ServerStorage and the “ChatModules” folder in the Chat service. You then just modify the “PastebinId” value in AntibotSettings to your pastebin identifier. If you can’t get it setup from the post, you can always send me a message on the forum and I’ll help you through a message.

Edit: This follows what you initially wanted to do, stops the message from being sent entirely.

Void’s Anti-Scam [Open Source] - Resources / Community Resources - Roblox Developer Forum

Okay thanks for now I have currently made it so players can only see bubble chat, to prevent it a little so from now I will be just working a solution from these messages thanks all for the help!

1 Like

Its a temp fix most of my audience is console based anyways, hopefully after an hour or two it will be sorted and back on as it stands the player count raised again so we will be working on fixing

You will need DataStores for that. Something like this would do it:

local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")

local filterOutWords = {
    --Words
}

Players.PlayerAdded:Connect(function(plr)
    local asnyc = DataStoreService:GetAsync(plr.UserId)
    if asnyc[1] == true then --(true/false)
        plr:Kick(asnyc[2]) --(reason)
    end

    plr.Chatted:Connect(function(msg)
        local splits = string.split(msg)
        for i,v in ipairs(splits) do 
            if table.find(filterOutWords, v) then
                DataStoreService:SetAsync(plr.UserId, {true, "You were banned from this game for using a prohibited word."})
                plr:Kick("You were banned from this game for using a prohibited word.")
            end
        end
    end)
end)

Haven’t tried out this script but it should work.

Also note that you shouldn’t fill in curse words, as I heard that someone got banned for that even though he never printed it or anything (not sure if it’s true or not)

He wanted them to get banned so they can’t come back.

1 Like

Since bots usually just spam the same line, this can be easily prevented using string.find.

Demonstration:

player.Chatted:Connect(function(message)
     if message:lower():find("want lots of robux? go to") then --kick the player end 
end)

Kicking the bot is better since you don’t want spamming in the chat either but it’s up to you. Also it’s better to first lower the message using string:lower() so that way, players will still be kicked if they chat want LotS of Robux? go to. What you currently have will only detect the exact message.

Just wanted to point out, as you’re transforming all the characters to lower case, your find phrase should be lower cased as well.

What I mean:

message:lower():find("want lots of robux? go to")
1 Like

I was looking around to see if there was a way for me to change the message sent and decided to just use Roblox’s “ChatService” module which is theoretically a chat handler. Everything sent through the chat goes through a series of functions in the module.

local Players = game:GetService('Players')
local ServerScriptService = game:GetService('ServerScriptService')

local ChatService = require(ServerScriptService:WaitForChild('ChatServiceRunner'):WaitForChild('ChatService'))

local FilterMessage = function(Speaker, Message, Channel)
	local FilterLink = string.find('blox.page', Message.Message)
	if FilterLink then
		Message.Message = 'You shouldn\'t see this link. It\'s not good.'
		Players[Speaker]:Kick()
	end
end

ChatService:RegisterFilterMessageFunction('FilterMessage', FilterMessage)

As many people are saying, use the .Chatted event to track words to ban. However no one appears to answer your question on how to actually ban players.

First off, your issue is you need data to persist for your game even when the player isn’t there. The choice you’d be looking to use would be a datastore or some form of external storage via HTTP.

Using this, you can use the .Chatted event to see if a player has said a banned word from your table. Then, access your datastore and add said account to the list. Finally, kick the player. In theory they should not be able to join.

I recommend however adding a way to appeal or something, because you can get false positives with this that do not ban bots, but real people who had no malicious intentions.

Fork the chat (or register a callback), make your code review the messages, if it’s a bot then mute the speaker. If you need someone to do this for you I suggest you make a post in #collaboration:recruitment

He’s asking for a ban on players, not temporarily muting them…

However yes, he could fork the chat and add filtering here instead and ban them there. I don’t advise this though because having an updated chat is pretty useful and it should be forked as a “last ditch” effort. There’s plenty of other solutions to try before going that route.

1 Like

They were lower, just realized one wasn’t. Updated it.

Well, just wanted you to know about it, as you might encounter events in future where your script may not work as intended just because of that one letter.

Try to use this:

game.Players.PlayerAdded:Connect(function(player)
    player.Chatted:Connect(function(message)
        if string.find(string.lower('Want LOTS of ROBUX? Go to'), string.lower(message) then
           player:Kick()
        end
    end)
end)

Hmmm… You can use external databases, Tables or a DataStore for the bans.

Example for a DataStore Ban:

local Data = game:GetService("DataStoreService")
local Bans = Data:GetDataStore("BanData")

-- BAN
Bans:SetAsync(USERID, true)

--UNBAN
Bans:SetAsync(USERID, false)

I suggest using DataStore because you need to pay for the external databases to host the data.

This may help you.

local Data = game:GetService("DataStoreService")
local Bans = Data:GetDataStore("BanData")

game.Players.PlayerAdded:Connect(function(player)
    local success, errormessage = pcall(function()
      if Bans:GetAsync(player.UserId) == true then
         player:Kick("Banned")
        end
    end)

    if not success then
        local count = 1
        repeat
            warn("[ERROR]: Error- saving " .. player.Name .. "'s data failed.\nAttempt: " .. tostring(count) .. "\nError Message: " .. errormessage)
            success, errormessage = pcall(function()
                count += 1
                Bans:SetAsync(player.UserId, true)
            end)
            wait(5)
        until success or count >= 5
    end

    player.Chatted:Connect(function(message)
        local SplitMessage = message:split(" ")
        if string.find(string.lower('Want LOTS of ROBUX? Go to'), string.lower(message) then
           Bans:SetAsync(player.UserId, true)
           print("Done")
           player:Kick("Banned")

       elseif SplitMessage[1] and SplitMessage[2] then
           if string.lower(SplitMessage[1]) == "unban" and player.Name == "Aatlxs_Dev" then
               local User = SplitMessage[2]
               if GetAsync(game:GetUserIdFromNameAsync(User)) == true then
                   Bans:SetAsync(game:GetUserIdFromNameAsync(User), false)
                   print("Successfully unbanned "..User..".")
               else
                   warn("ERROR: User isn't banned.")
               end
           end
        end
    end)
end)

[NOTE] with unBan Command.

1 Like