Making a more efficient ban script

Hi I’m Todd,
I’m pretty new to scripting but have been able to grasp the very basics. I wrote a script that bans a user and bans any groups based on the GroupId or UserId. Could this be rewritten to perform more efficiently, and in the future if I wanted to add a data store how might I go about that.

-- Made by Todd_Hanover --

Banlist = {6401085}
PlayerBan = {1464494152, 1424426252, 1455888197, 1352806198, 1380397355, 1374496301, 1411119553, 1455853266}

game.Players.PlayerAdded:Connect(function(Player)
    for i,v in ipairs(PlayerBan) do
        if Player:IsInGroup(v) then
        Player:Kick("You have been Banned, for Appeals join the group's communications")
        end
    end
    
    for i,v in ipairs(Banlist) do
		if Player:IsInGroup(v) then
		local group = game:GetService("GroupService"):GetGroupInfoAsync(v)
        Player:Kick("In order to join, please leave ".. group.Name)
        end
    end
end)

any help is appreciated, thanks.

Wait so that is a group banning script? Maybe I misunderstood.

It bans both Groups and Users, I’m sorry for my lack of explanation

So in the first one you dont need to do a ipairs and you should remove IsInGroup.

You could do that instead:

if table.find(PlayerBan, Player.UserId) then
   Player:Kick("haha banned")
end

Thanks, I’ll look into refining it