Module script, table

Hello,
So i am trying to develop an Anti-cheat but actually i don’t know how to use table ( to whitelist some things. )

Here’s the code :

Module Script :

local AntiCheatConfig = {}

--[[

Client and Server side anti-cheat.
Developped by : Le Noirrateur.
CreationDate : 26/08/2023.

############################################################
###########################[Usage]##########################
############################################################

1. Place the script into ReplicatedStorage.
2. Register scripts
]]

AntiCheatConfig.Settings = {
	
	-- Ban user if cheat
	BanUsers = false, -- Set to true to ban the player ( don't forget to set KickUsers to false )
	BanMessage = [[Your account has been banned.
	
	Reason: Injecting - Cheating
	Duration: Permament ban
	
	If nothing of this has happened, contact the game moderation.]],
	
	-- Kick User if cheat
	KickUsers = true, -- Set to true to kick the player ( don't forget to set BanUsers to false )
	KickMessage = [[A Problem with your Roblox client has been detected.
	(maybe cheats or unregistered script...)]],
	
	DeleteScript = true,
	
}

AntiCheatConfig.RegistredScripts = {
	{
		Name = "YesWorkingScript",
		Location = "game.Workspace.Part.Part.Button",
		Id = 123456789
	},
	{
		Name = "Empty",
		Location = "game.Workspace.Empty",
		Id = 123456789
	}
}

return AntiCheatConfig

Script :

local AntiCheat = require(script.Parent)

function noRegistredScript(player, scriptLocation, scriptName)
	warn("The player "..player.Name.." has registered script :")
	warn("script Location :"..scriptLocation)
	warn("script Name"..scriptName)
	if AntiCheat.Settings.DeleteScript then
		game:FindFirstChild(scriptLocation):Destroy()
	end
	
	if AntiCheat.Settings.BanUsers then
		print("Banning the user...")
		player:Kick(AntiCheat.Settings.BanMessage)
	end

	if AntiCheat.Settings.KickUsers then
		print("Kicking the user...")
		player:Kick(AntiCheat.Settings.KickMessage)
	end
end

game.ReplicatedStorage.scriptFounded.OnServerEvent:Connect(function(player, scriptLocation, scriptName)
	warn("Executing removeEvent")
	for _, scriptInfo in pairs(AntiCheat.RegisteredScripts) do
		warn("Getting scripts informations")
		if scriptInfo.Location == scriptLocation then
			warn("True to location")
			if scriptInfo.Name == scriptName then
				warn("true to name")
				return
			else
				warn("False to name")
				noRegistredScript(player, scriptLocation, scriptName)
			end
		else
			warn("False to location")
			noRegistredScript(player, scriptLocation, scriptName)
		end
	end
end)

and using this i get an error :

ServerScriptService.AntiCheat.Executor:24: invalid argument #1 to ‘pairs’ (table expected, got nil) - Serveur
Stack Begin - Studio
Script ‘ServerScriptService.AntiCheat.Executor’, Line 24 - Studio
Stack End - Studio

1 Like

Hello Noirrateur! This problem was caused because in the foreach you did a typo.

Here is the code:

local AntiCheat = require(script.Parent)

function noRegistredScript(player, scriptLocation, scriptName)
	warn("The player "..player.Name.." has registered script :")
	warn("script Location :"..scriptLocation)
	warn("script Name"..scriptName)
	if AntiCheat.Settings.DeleteScript then
		game:FindFirstChild(scriptLocation):Destroy()
	end

	if AntiCheat.Settings.BanUsers then
		print("Banning the user...")
		player:Kick(AntiCheat.Settings.BanMessage)
	end

	if AntiCheat.Settings.KickUsers then
		print("Kicking the user...")
		player:Kick(AntiCheat.Settings.KickMessage)
	end
end

game.ReplicatedStorage.scriptFounded.OnServerEvent:Connect(function(player, scriptLocation, scriptName)
	warn("Executing removeEvent")
	for _, scriptInfo in pairs(AntiCheat.RegistredScripts) do
		warn("Getting scripts informations")
		if scriptInfo.Location == scriptLocation then
			warn("True to location")
			if scriptInfo.Name == scriptName then
				warn("true to name")
				return
			else
				warn("False to name")
				noRegistredScript(player, scriptLocation, scriptName)
			end
		else
			warn("False to location")
			noRegistredScript(player, scriptLocation, scriptName)
		end
	end
end)

In your Module the name of the table is “RegistredScripts” and in your foreach it was “RegisteredScripts”.

2 Likes

bruh thx i didn’t noticed i am really dumb.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.