Banning and Admining System is Not Working and I Can Not Revert My Script

  1. What do you want to achieve? I want to make a banning and admin system using datastores.

  2. What is the issue? Whenever I join I get banned for some reason even though nobody is added to either of the datastores. I don’t know how to fully describe everything that’s gone wrong because I’ve dug myself and the script so deep into a hole.

--CUSTOMIZABLE THINGS
local prefix = "/"

--SERVICES AND LOCATIONS	
local storage = game:GetService("ReplicatedStorage")
local dataStores = game:GetService("DataStoreService")
local banStore = dataStores:GetDataStore("BanStore")
local adminStore = dataStores:GetDataStore("AdminStore")

local whitelist = require(script:WaitForChild("Whitelist"))

--COMMAND LIST
local commands = {}

--FUNCTIONS AND THE CODE ITSELF
local function isAdmin(plr, admins) --OBJECT VERSION OF PLR
	for _, v in pairs(whitelist) do
		if v == plr.UserId then
			return true
		end
	end
	for _, v in pairs(adminStore) do
		if v == plr.UserId then
			return true
		end
	end
	return false
end

local function findPlrs(name, sender)
	name = name:lower()

	local plrs = game.Players:GetPlayers()
	local targets = {}

	for i, plr in pairs(plrs) do
		if plr.Name:lower():sub(1,#name) == name:lower() then
			table.insert(targets, plr)
			break
		end
	end

	if name == "me" then
		table.insert(targets, sender)
	elseif name == "all" then
		for i, plr in pairs(plrs) do
			table.insert(targets, plr)
		end
	elseif name == "others" then
		for i, plr in pairs(plrs) do
			if plr.Name ~= sender.Name then
				table.insert(targets, plr)
			end
		end
	elseif name == "admins" then
		for i, plr in pairs(plrs) do
			if table.find(adminStore:GetAsync(plr.UserId), plr.UserId) then
				table.insert(targets, plr)
			end
		end
	elseif string.find(name, ",") then
		local split = string.split(name, ",")

		for i, plr in pairs(plrs) do
			for _, individual in pairs(split) do
				if plr.Name:lower():sub(1,#name) == individual:lower() then
					table.insert(targets, plr)
				end
			end
		end
	end

	return targets
end

commands.admin = function(sender, args)
	print("Admin function fired by "..sender.Name)
	local plrToAdmin = args[1]
	if plrToAdmin then
		local plrToAdmin = findPlrs(plrToAdmin, sender)
		if next(plrToAdmin) then
			for _, v in pairs(plrToAdmin) do
				local plrId = game.Players:GetUserIdFromNameAsync(v)
				adminStore:SetAsync(plrId, true)
				print(v.." has become an admin!")
			end
		end
	end
end

commands.ban = function(sender, args)
	print("Ban function fired by "..sender.Name)
	local plrToBan = args[1]
	if plrToBan then
		local plrToBan = findPlrs(plrToBan, sender)
		if next(plrToBan) then
			for _, v in pairs(plrToBan) do
				local plrId = game.Players:GetUserIdFromNameAsync(v)
				banStore:SetAsync(plrId, true)
				v:Kick("You have been banned for "..args[2])
			end
		end
	end
end

commands.kick = function(sender, args)
	print("Kick function fired by "..sender.Name)
	local plrToKick = args[1]
	if plrToKick then
		local plrToKick = findPlrs(plrToKick, sender)
		if next(plrToKick) then
			for _, v in pairs(plrToKick) do
				v:Kick(args[2])
				print(v.Name.." got kicked for "..args[2])
			end
		end
	end
end

commands.speed = function(sender, args)
print("Speed function fired by "..sender.Name)
local plrToSpeed = args[1]
local walkSpeed = args[2]
if plrToSpeed and walkSpeed then
	local plrs = findPlrs(plrToSpeed, sender)
	if next(plrs) then
		for i,v in pairs(plrs) do
			v.Character.Humanoid.WalkSpeed = tonumber(walkSpeed)
			print(v.Name.." was given WalkSpeed ".. walkSpeed)
		end
	end
end
end

commands.tp = function(sender, args) --SENDER IS AN OBJECT | ARGS ARE TABLE OF STRINGS
	print("Teleport function fired by "..sender.Name)
	for _, plrName in pairs(args) do
		print(plrName)
	end
	local plrTpingName = args[1]
	local plrTpingToName = args[2]
	if plrTpingName and plrTpingToName then
		local plrTping = findPlrs(plrTpingName, sender)
		local plrTpingTo = findPlrs(plrTpingToName, sender)
		for i,v in pairs(plrTping) do
			v.Character.HumanoidRootPart.CFrame = plrTpingTo[1].Character.HumanoidRootPart.CFrame
			print("Teleport Successful")
		end
	end
end

commands.unadmin = function(sender, args)
	print("Unadmin function fired by "..sender.Name)
	local plrToUnadmin = args[1]
	if plrToUnadmin then
		local plrId = game.Players:GetUserIdFromNameAsync(plrToUnadmin)
		adminStore:RemoveAsync(plrId)
		print(args[1].." is no longer an admin!")
	end
end

commands.unban = function(sender, args)
	print("Unban function fired by "..sender.Name)
	local plrToUnban = args[1]
	if plrToUnban then
		local plrId = game.Players:GetUserIdFromNameAsync(plrToUnban)
		banStore:RemoveAsync(plrId)
		print(args[1].." is no longer banned!")
	end
end

game.Players.PlayerAdded:Connect(function(plr)
	local admins = adminStore:GetAsync(plr.UserId)
	
	local data = banStore:GetAsync(plr.UserId)
	for _, v in pairs(whitelist) do
		if data ~= v and data ~= false then
			plr:Kick("You stupid? You are banned!")
		end
	end
	plr.CharacterAdded:Connect(function()
		plr.Chatted:Connect(function(msg, recipient)
			if isAdmin(plr, admins) then
				msg = string.lower(msg)
				local splitString = msg:split(" ")
				local arg1 = splitString[1]
				local cmd = arg1:split(prefix)
				local cmdName = cmd[2]
				if commands[cmdName] then
					local args = {}
					for i = 2, #splitString, 1 do
						table.insert(args, splitString[i])
					end
					commands[cmdName](plr, args)
				end
			end
		end)
	end)
end)
  1. What solutions have you tried so far? I’m extremely stressed right now and mad and I couldn’t find anything even if I wanted to.

Maybe its because the first time u join to a game, data == nil and so if data is not == false u ban them so the first time a player gets added u should set their data to false… dunno if u understood me hopefully i help!..
Or instead just add another and

local data = banStore:GetAsync(plr.UserId)
	for _, v in pairs(whitelist) do
		if data ~= v and data ~= false and data ~= nil then
			plr:Kick("You stupid? You are banned!")
		end
	end

1 Like

ok this fixed the banning issues… but my admining and banning commands still do not work whatsoever, but I was able to check the admin dataStore and the player named “Instance” was banned, I assume this has to do with some item named “instance” slipping through? im so confused