I need help with a Ban Script, any help is appreciated

As a Novice Scripter I’ve been learning how to make basic scripts such as this ban script, everything works so far but everything isn’t perfect. Currently my “Exceptions” List is works off of a players UserId. I wanted to change it from specific Users to a Group. If I’m not making much sense please feel free to reply below and I’ll go into more detail with what I was hoping I could do. Any help is appreciated.

-- Made by Todd_Hanover --

GroupBan = {5690006, 3755309, 7288513, 3324269, 3999579, 3781245, 6245567, 6308981, 7150012, 
6763992, 5923159, 5256894, 7648367, 6864318, 7247385, 7677580, 7838941, 6655521, 7935643, 
2902364, 7953092, 7955524, 7881661, 7601108, 7526275}
PlayerBan = {1464494152, 1424426252, 1455888197, 1352806198, 1380397355, 1374496301, 
1411119553, 1455853266}
Exceptions = {}

game.Players.PlayerAdded:Connect(function(Player)
    for i,v in ipairs(PlayerBan) do
	    if table.find(PlayerBan, Player.UserId) then
		    Player:Kick("You have been Banned, for Appeals join American Civil War Community's Communications.")
	end
end

    for i,v in ipairs(GroupBan) do
	    if Player:IsInGroup(v) and not table.find(Exceptions, Player.UserId) then
		    local group = game:GetService("GroupService"):GetGroupInfoAsync(v)
		    Player:Kick("In order to join, please leave ".. group.Name)
	    end
    end
end)
1 Like

Are you trying to create a list of group exceptions to bypass the GroupBan table?
Why are you making a list of exceptions? Just remove the Id from either the GroupBan or PlayerBan tables. I guess I’m confused on what you’re trying to accomplish, some elaboration would be very helpful :smiley:

1 Like

I have both a Player ban which uses a UserID, then I have a Groupban which uses a GroupID, but I want to add an Exception, so that anyone inside my group isn’t banned. I want to have it so if they are in the “Exception Group” but also in a banned group, they may still join my game. As Bizarre as that sounds its something which made sense in my head.

1 Like

Ok, I understand now. That makes more sense :sweat_smile:
Here’s some semi-pseudocode that may outline a potential solution

local bannedGroups = {123, 456, 789}
local bannedPlayers = {111, 222, 333}
local groupExceptions = {321}

game.Players.PlayerAdded:Connect(function(player)
	-- Check for player ban
	for _, bannedPlayer in pairs(bannedPlayers) do
		if player.UserId == bannedPlayer then
			-- Kick player
		end
	end
	-- Check for group ban
	for _, bannedGroup in pairs(bannedGroups) do
		if player:IsInGroup(bannedGroup) then
			-- Check if they are excepted
			for _, exceptedGroup in pairs(groupExceptions) do
				-- If they are, break out of the loops
				if player:IsInGroup(exceptedGroup) then
					return
				end
			end
			-- If the player isn't in an excepted group, the code will reach here
			-- Kick player
		end
	end
end)

I haven’t tested this, but I believe it should work?

2 Likes

Personally I would check to see if they’re in the exception group first before running through the groups.

local PlayerBans = {14214}
local GroupBans = {12144}
local GroupExceptions = {12414}
local Players = game:GetService('Players')

local function CheckException(Player)
	for i,v in next, GroupExceptions do
		if Player:IsInGroup(v) then
			return true
		end
	end
	return false
end
Players.PlayerAdded:Connect(function(Player)
	for i,v in next, PlayerBans do
		if Player.UserId == v then
			Player:Kick('ya banned kid idk why')
		end
	end
	if not CheckException(Player) then
		for i,v in next, GroupBans do
			if Player:IsInGroup(v) then
				Player:Kick('ya in a banned group kid')
			end
		end
	end
end)
1 Like

The exceptions array is an array of players who’d be immune to the group ban according to the OP’s code.

1 Like

Don’t know who you’re replying to, but if you’re replying to mine that’s why I’m running the group exception before running group ban.

It is, however I was originally trying to figure how I could make it a group exception rather than having to add everyone’s UserID individually.