Ban Check Script Not Working

So, I have created an Admin Panel System and I was trying to create an admin panel ban system. The only part of this is the ban checking script that doesn’t seem to work.

Fixed Code:

local DSS = game:GetService("DataStoreService")
local Bans = DSS:GetDataStore("AdminSystems_Ban")
local Banned = {"Aiden_12114"}

return function()
	print("Banning Loaded")
	while true do
		wait(30)
	for _,v in pairs(game.Players:GetPlayers()) do
		if table.find(Banned, v) then
			 v:Kick("\n\nAdminSystems Alpha\nYou Are Banned From This Game!")
		end
	end
	end
end

I’m not sure what’s wrong though… (I Just Learnt for i,v in pairs() do)

About The “Use UserID” Chat.

I am going to implement a use of UserID instead of Username so, please stop talking about it.

Sorry! I seem to have fixed it!

local DSS = game:GetService("DataStoreService")
local Bans = DSS:GetDataStore("AdminSystems_Ban")
local Banned = {
	"Player1"
}

return function()
	print("Banning Loaded")
	while true do
		for _, v in pairs(game.Players:GetPlayers()) do
			if table.find(Banned, v.Name) then
				v:Kick("\n\nAdminSystems Alpha\nYou Are Banned From This Game!")
			end
		end
		wait(30)
	end
end

these are called generic loops, the pairs function allows iteration over key-value pairs, the placeholder i or v can be anything you want btw, not just i,v…

if you don’t need the index later on use ipairs, you’re using numerical indices
anyways.

You also aren’t using the DataStore at all here , you could just keep the table containing the Banned players’ ids and remove the DataStore(?).

1 Like

Yes, I know that. I just said i,v for example purposes :smiley:

I changed it to _, Players

a bit out of context, but you should ban player by their id instead of username
seen in the script

1 Like

Exactly there are games that didn’t do this before, and it let players change their name and get unbanned. It would cost them 1,000R$ to do this, but they would still get unbanned.