Ban script using a module script doesn't work

I’m trying to make a ban/group ban/whitelist script that uses 1 modulescript and tables in that module script to make the list just in 1 script and not spread across multiple, but it doesn’t work but it doesn’t throw any errors either, if anyone more familiar with module scripts can correct anything I’d be happy :sweat:

MODULE

local Lists = {}

local Bans = {}
local Allowlist = {}
local Blacklist = {}

Bans.Players = {
	[uid] = "reason";

Bans.Groups = {
	[groupid] = groupid;
}

Bans.WatchlistGroups = {
	-- [group id] = group id (again), watchlist code
	[0] = 0, 1;
}

Allowlist.Players = {
	[uid] = uid;
}

Blacklist.Players = {
	[uid] = "reason";
}

function Lists.CheckAllowlist(uid)
	user = table.find(Allowlist.Players, uid)
	return user
end

function Lists.CheckBlacklist(uid)
	user = table.find(Blacklist.Players, uid)
	return user
end

function Lists.CheckBan(uid)
	user = table.find(Bans.Players, uid)
	return user
end

function Lists.CheckGroupBan(gid)
	group = table.find(Bans.Groups, gid)
	return group
end

function Lists.CheckWatchlist(gid)
	group = table.find(Bans.WatchlistGroups, gid)
	return group
end

function Lists.RtnGroupTable()
	return Bans.Groups
end

function Lists.RtnWatchlistTable()
	return Bans.WatchlistGroups
end

return Lists

BANS SCRIPT

local Bans = require(script.Parent.Lists)

local WatchlistEvent = game.ReplicatedStorage.Watchlist
game.Players.PlayerAdded:Connect(function(plr)
	for _, group in pairs(Bans.RtnGroupTable()) do
		if plr:IsInGroup(group) then
			local GroupInfo = game:GetService("GroupService"):GetGroupInfoAsync(group)
			plr:Kick("in a banned group")
		end
	end
	if Bans.CheckBan(plr.UserId) then
		plr:Kick("banned")
	end
	for _, group in pairs() do
		if plr:IsInGroup(group) then
			local GroupInfo = game:GetService("GroupService"):GetGroupInfoAsync(group)
			if GroupInfo.Id ~= 0 then
				WatchlistEvent:FireClient(plr, GroupInfo.Name, Bans.RtnWatchlistTable()[1])
			end
		end
	end
end)

WHITELIST SCRIPT

local AllowList = require(script.Parent.Lists)

game.Players.PlayerAdded:Connect(function(plr)
	if script.Whitelist.Value == true then
		if script.DevSite.Value == true then
			if plr:GetRankInGroup(groupid) <= 252 then
				if AllowList.CheckAllowlist(plr.UserId) then else
					plr:Kick("whitelist")
				end
			end
		else
			if plr:GetRankInGroup(groupid) <= 2 then
				if AllowList.CheckAllowlist(plr.UserId) then else
					plr:Kick("whitelist")
				end
			end
		end
	end
end)

Ah, the problem is you’re making dictionaries {key1 = apple, key2 = orange, key3 = banana}, and not arrays {key1, key2, key3} while using table.find which only works for arrays. You can convert the dictionaries to arrays or just use for example group = Bans.Groups[gid] instead of the table.find

1 Like

There’s quite a few bugs / issues / half written code here, so I’ve rewritten your code, here’s my version:

Script:

-- Services
local Players = game:GetService("Players")

-- Modules
local ListModule = require(script.Parent.Lists)

Players.PlayerAdded:Connect(function(Player) -- Player joined connection
	
	local UserId = Player.UserId -- Get UserId
	
	if ListModule.CheckBan(UserId) then
		return Player:Kick("banned")
	end
	
	if ListModule.CheckGroupBan(Player) then
		return Player:Kick("In a banned group")
	end
	
	if ListModule.WhitelistEnabled then
		
		if ListModule.DevSite then
			
			if not (Player:GetRankInGroup(ListModule.WhitelistGroup) <= ListModule.DevRank or ListModule.CheckWhitelist(UserId)) then
				return Player:Kick("whitelist")
			end
			
		else
			
			if not (Player:GetRankInGroup(ListModule.WhitelistGroup) <= ListModule.WhitelistRank or ListModule.CheckWhitelist(UserId)) then
				return Player:Kick("whitelist")
			end
			
		end
	end
	
end)

Module:

local Lists = {}

-- Bans / Whitelist
local Bans = {}
local Whitelist = {}

-- Settings
Lists.WhitelistEnabled = true
Lists.DevSite = true
Lists.WhitelistGroup = 0 -- Make this whatever group you're trying to whitelist
Lists.DevRank = 252 -- Make this the rank of who you want to ignore "DevSite"
Lists.WhitelistRank = 2 -- Make this the rank of who you want to ignore "WhitelistEnabled"

-- Whitelist / Bans
Bans.Players = {} -- UserId's you want banned
Bans.Groups = {} -- GroupId's you want banned
Whitelist.Players = {} -- UserId's you want to whitelist for devsite access / whitelist access

function Lists.CheckWhitelist(uid) -- Check if the player is in the whitelist table
	return table.find(Whitelist.Players, uid)
end

function Lists.CheckBan(uid) -- Check if the player is in the bans table
	return table.find(Bans.Players, uid)
end

function Lists.CheckGroupBan(Player) -- Check if the player is in a banner group
	for _, Group in pairs(Bans.Groups) do
		if Player:IsInGroup(Group) then
			return true
		end
	end
	return false
end

return Lists

Note: What not_log1c said is also correct, please use an array layout for your bans.

Example:
Bans.Groups = {0,243432,21323654,34324}
Bans.Players = {0,1,2,3}

1 Like