Why is my ban script not activating?

Achieve

I’m attempting to make a ban system through a module script.

Issue

The ban system doesn’t activate. I attempted to test the system through using my own name and it doesn’t work.

Module Script

---------[Bans]--------
--[I recommend using the BanID over the name due to the name changing ability.]--
local BanIDs = {}
local BanNames = {"MillerrIAm"}
local playerCheck = {}
function playerCheck.Banned(plr)
	for i,BanID in ipairs (BanIDs) do
		for i,BanName in ipairs (BanNames) do
			if Players:GetUserIdFromNameAsync(plr.Name) == BanID then
				print("Banned: "..plr.Name.." tried to join the game.")
				plr:Kick("You are banned from this game.")
				return true
			elseif Players:GetNameFromUserIdAsync(plr.UserId) == BanName then
				print("Banned: "..plr.Name.." tried to join the game.")
				plr:Kick("You are banned from this game.")
				return true
			end
		end
	end
end

return playerCheck

Player Check Script

--Made By MillerrIAm
--------Variables-------
local GUIName = "ControlUI" --[Change this to the name of your controls.]--
local plr = game:GetService("Players")
local playerCheck = require(game.ServerScriptService["Scripts|Admins"]["ModuleScript|AdminCheck"])
--------Main Code------
--[ControlUI Protocol]
plr.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		if playerCheck.AdminUI(player) then
			plr.PlayerGui[GUIName]:Destroy()
		end
	end)
end)
--[Ban Protocol]
plr.PlayerAdded:Connect(function(player)
	if playerCheck.Banned(player) then
		warn("Banlist Protocol Activated.")
	end
end)
--[Whitelist Protocol]
plr.PlayerAdded:Connect(function(player)
	if playerCheck.Whitelist(player) then
		warn("WhiteList Protocol Activated.")
	end
end)

Thank you for any help you can give me

1 Like

You are not calling your function in this script as it has not been correctly defined in the module script.
You would need to change it to look like this:

local module = {}
module.playercheck = function()

end
return module

This script could however be much more simplified by using a for loop, for example:

----Module script
local module = {}

module.BanIDs = {}
module.BannedPlayers = {'someoneyoudislike'}

return module

-----Server script
local MODULE = require(game.ServerScriptService.Module)

game.Players.PlayerAdded:Connect(function(plr)
    for _,v in pairs(MODULE.BanIDs) do
         if plr.UserId == v then
         plr:Kick()
    end

    for _,v in pairs (MODULE.BannedPlayers)do
       if plr.Name == v then
      plr:Kick()
    end
end)

Hope this is able to help!

A few issues right off the bat:

You are writing a function to a nil value which does nothing, and on top of that, you aren’t returning your module, I’ve fixed both of those here below.

local playerCheck = {}
---------[Bans]--------
--[I recommend using the BanID over the name due to the name changing ability.]--
local BanIDs = {}
local BanNames = {"MillerrIAm"}

function playerCheck.Banned(plr)
	for i,BanID in ipairs (BanIDs) do
		for i,BanName in ipairs (BanNames) do
			if Players:GetUserIdFromNameAsync(plr.Name) == BanID then
				print("Banned: "..plr.Name.." tried to join the game.")
				plr:Kick("You are banned from this game.")
				return true
			elseif Players:GetNameFromUserIdAsync(plr.UserId) == BanName then
				print("Banned: "..plr.Name.." tried to join the game.")
				plr:Kick("You are banned from this game.")
				return true
			end
		end
	end
end

return playerCheck

Fixing that should make the entire thing function as intended.

Apologies as I am on mobile, but it is unnecessary to loop through a table when there is table.find() which is much shorter. Here is the code using it.

local playerCheck = {}
---------[Bans]--------
--[I recommend using the BanID over the name due to the name changing ability.]--
local BanIDs = {}
local BanNames = {"MillerrIAm"}

function playerCheck.Banned(plr)
    if table.find(BanIds, plr.UserId) or table.find(BanNames, plr.Name) then
        plr:Kick(“You are banned from this game.”)
        return true
    else
        return false
    end
end

return playerCheck

Apologies if this looks ugly as I am on mobile.

There is a specific reason why I use certain aspects, the main one being… exploiters. I thank you for this recommendation but I don’t use the table.find() due to the easily exploitable situation this brings.

What do you mean by exploiters?

table.find() is just a method, nothing worse,
both are the same thing except you need to just make sanity checks to make sure it isn’t exploitable

Could you please describe or show an example of what you mean please?

That means using pairs loop or table.find doesn’t really matters and none is related to being exposable to the exploiters, even if it is some data sent from a local script, it is still the same for pairs loop.

I am referencing your statement of not suggesting table.find() because it is easily exploitable.

I understand that but due to me using the Async features… i’m unable to use the table.find method. I use the Async features so exploiters when they change their UserId or Name in game which yes… they are able to do. Then this will force a site check instead of relying on the client which can be unreliable at times.

This is a server script, correct? If so, any changes made on the client do not replicate to the server if you use filtering enabled.