Is there anything which I've messed up on / need to add?

Hello,

I’m developing a anti-scam bot script that stops scam-bots from tricking the younger side of Roblox (4-7 years old). But I wanted to know if I could make the scripts more hybrid and the length of them to be shortened, I also used string.sub and string.match which I’ve never used before so corrections would be appreciated.

-Starter Gui Script

local player = game.Players.LocalPlayer
local players = game:GetService('Players')
local DataStore = game:GetService('DataStoreService')

--Please remember to credit me. (Cinema_Sin (subject to name change may vary.))
local player = game.Players.LocalPlayer
game.Players.PlayerAdded:Connect(function(plr)
		
		local InfoFolder = Instance.new('Folder')
		InfoFolder.Name = 'PlayerInfo'
		InfoFolder.Parent = plr
		
		local BanBool = Instance.new('BoolValue')
		BanBool.Name = 'BanBool'
		BanBool.Value = false
		BanBool.Parent = InfoFolder
		
		
		local name = plr.Name
		local scamWebsitesTable = {
			
			'fastbucks.me'
			 -- Feel free to add more scam websites
			
			}
		
		
		    game.Players.LocalPlayer.Chatted:Connect(function(msg)
			    if string.sub(msg, 1, 150) == '/me just got TONS of ROBUX using '..scamWebsitesTable..'!'..'Visit '..scamWebsitesTable..' in your browser to generate robux instantly!' or string.match('[/me just got TONS of ROBUX using! Visit* '..scamWebsitesTable..' [in your browser to generate robux instantly!*', scamWebsitesTable and '[Visit*' and '[/me*' and '[ROBUX*' and '[robux*')then
				  
				  warn('Banning in progress.')
				  BanBool = true
				 
				  local BanReason = 'Dont break the games rules. Please read Robloxs ToS if you are unsure on the rules.'
				  local enforceBan = true
				  local Banner = 'The smart game.'
					
				if BanBool == true then
					player:Kick('You got banned by '..Banner..' Reason: '..BanReason)
					
					wait()
					warn('Banning completed. :)')
				else
					warn('Banning failed. :(')
				end
				
			end
		end)
	end)

Thanks for reading :slight_smile:

1 Like

First off, just a general tip. You’re creating the scamWebsitesTable table every time a new player joins, and that’s not needed :slight_smile:

Secondly, you’re hardcoding when checking if the player chats something, you’re checking if the message is exactly like the 150 first characters, again not needed.

Thirdly, you’re creating a BoolValue and a Folder when you can do it by using tables.

Fourthly, you’re doing string concatenation, in your example, it does no harm, but it’s:

  1. Ugly
  2. Bad way / habit

Fifthly, you’re doing this on the client, I think I know what you think, since the bots are just bots, they’re not exploiters. But, this also results in the kick message to be redundant, bots don’t read error messages!

Well, now I’ve talked about the points I feel are the most important ones. Well, what can we do about it? Yes, we can rethink the whole process and this time, do it on the server and write code that looks better!

Okay, now you have to decide if you want to use Bayes’ theorem to find out if a string is very similar to something else, or if you just want to block certain keywords. I will show you both, for your convenience.

Blocking keywords

Blocking keywords


First off, just have the table in a ModuleScript or at the top of the script. For the sake of this tutorial, I’m using a standard table in the script. I also renamed the table to be blockedWords, because that makes sense, right?

local blockedWords = {
   "link1",
   "robux"
};

Great, our keyword table. Now, what we would like to do next, is to check if anyone says one of these keywords, and then you can choose an action of your liking.

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

Players.PlayerAdded:Connect( function (newPlayer) 
    newPlayer.Chatted:Connect( function (newMessage)

        -- Go through each blocked keyword and see if it matches the message
        for index, word in pairs(blockedKeywords) do
            if newMessage:lower():match(word) then
                -- // Found keyword, do something!
            end
        end

    end)
end)

Combining the script it pretty much looks like this:

Code
-- // Services
local Players = game:GetService("Players");

-- // Misc. variables
local blockedWords = {
   "link1",
   "robux"
};

Players.PlayerAdded:Connect( function (newPlayer) 
    newPlayer.Chatted:Connect( function (newMessage)

        -- Go through each blocked keyword and see if it matches the message
        for index, word in pairs(blockedKeywords) do
            if newMessage:lower():match(word) then
                -- // Found keyword, do something!
            end
        end

    end)
end)
Using Bayes' theorem

Library: https://github.com/leafo/lapis-bayes

You can use Bayes’ to “categorize” strings, the downside with this is that you have to “train” it to do so. It’s not necessarily difficult, but it takes time.

Taking point from the “Blocking keywords” section of this post, after a player has chatted, you can categorize the message.

Example:

.Chatted:Connect( function (newMessage)
    local category = bayes.classify_text(newMessage:lower());
    -- // Depending on what you trained it to:
    --> Spam / Ham
end)

It explains pretty much everything on the GitHub page, but for the “lazy” people, you train it using bayes.train_text.

Examples:
(Please note this is hardcoding, the best would be to use a table and iterate through it and “feed” it)

bayes.train_text("spam", "i just got tons of robux, visit this site");
bayes.train_text("spam", "free robux, no account needed");
bayes.train_text("spam", "giving away tons of robux, visit this page");

bayes.train_text("ham", "this game is amazing");
bayes.train_text("ham", "this game sucks");
bayes.train_text("ham", "tow do I play this game, i can't find the tutorial");

As far as I understand how this theorem works, is that it goes through each word in the strings you feed it, and sort of maps them and counts how many times it is used. Then once you want it to categorize, it does the same, but just checks and then “weighs” the string.

You might also see that I entered all the strings as lowercase letters, that’s because it is case-sensitive.

5 Likes

Adding onto @WhereAreTheLights’s post, you should never hardcode something like that. All it takes is for the bot manager to change one character to make your whole script is now useless. In cases like this, you should always be general.

Although the “Blocking keywords” method is way more understandable, as a machine learning enthusiast, it would be great if you could implement Bayes’ theorem as the machine will do the thinking, not you. Utilizing the Bayes’ theorem, you won’t have to add new keywords every time a scammer changes their messages as the algorithm will still pick it up as it searches for patterns, not keywords. Ah, the beauty of machine learning.

I hope your script turns out beautifully!

1 Like

I’ll redo the code, thanks for the tips and help though. :blush:

If I can train the machine to do whatever, could I use it to make an advanced AI?

I don’t understand why you make a code that work for only ONE message type…
I made a Script recently that can find anything that can be suspect:

--Define all suspect 'words' with a Kick Point value
local OutMatch = {"/me",2,"just got tons of robux",4,"at this link",4,
	"got tons of robux using",8,"get your promo for robux",8,"robux now for free",8,
	"redeem game passes & r$ instantly",8,"r$ instantly",8,
	"go to the link",8,"go to this link",8,
	"fastbucks.me",8,"robuxcodes.me",8,"dailyreward.me",8,"rewardbuddy.club",8,"rewardtool.se",8,"robuxcodes.me",8,"gobux.me",8
}

game.Players.PlayerAdded:Connect(function(Plr)
	local i=0
	local KickP=0 --Kick Points
	if Plr:WaitForChild("Passes"):WaitForChild("Locked").Value then --Only for my game... Ignore that
		wait(4)
		Plr:Kick("You are locked") --Yeah!
	else
		Plr.Chatted:Connect(function(Msg) --From there, the script is checking the chat
			local FMsg = string.lower(Msg) --Formatted message to ignore case
			for i=1,#OutMatch/2 do
				if not (string.find(FMsg,OutMatch[i*2-1])==nil) then --Looking for a match
					KickP = KickP+OutMatch[i*2] --Add the Kick Point value of the match
				end
			end
			if KickP >= 16 then --If the player get too much Kick Points, he get Kick (with his Score!)
				Plr:Kick("\nDon't write inappropriate messages!\nYou got "..KickP.." Kick Points!")
			end
		end)
	end
end)
2 Likes

You can change the Kick Point value of the matches if you want instant-kick or else…

It depends on what kind of AI you mean. You have to train AIs for a specific purpose. Bayes’ theorem isn’t an AI, but rather an algorithm. Creating a real AI is more difficult and requires you to to understand how it works at a decent level.

Oops, I mist Baye’s :sweat_smile:
So my algorithm is just using key words and make a “kick score” to determine if he must kick or not…
It’s very simple and very flexible because it will look for scam websites and messages that can incite going to thes websites, so if you are saying that “Fastbucks.me is a Scam” it won’t kick instantly…
I should add that when you say “… is a scam” it remove 8 kick points

Yeah, I just wanted to experiment with AI tech. NPC’s for example.

I’m thinking about an AI that can make automatics-animations using physics!
Tell the AI to stay up or walk with a R15 Character but to open doors it’s better to use a custom character

So I can upgrade my Script with an AI that would be able to understand when to kick properly…

Good idea, I was thinking about an NPC that can detect walls and stuff, go through doors, basically a robot styled AI system. (Also, It learns from it’s mistakes!) One last thing, how do I install Bayes’ theorem onto studio?

1 Like

Uh :ohmy:, I use always code provided by myself or someone’s code that I customized :neutral_face: