Issue with my admin commands: kick & ban won't work

Title is self explanatory, no errors in the console or output.

CODE

local config = require(game:GetService("ServerScriptService").Solar.Setup:FindFirstChild("Config"))
local Datastores = game:GetService("DataStoreService")
local PlayerService = game:GetService("Players")
local ServerBan = {}

function CheckPermLevel(userId)
	local PlayerKey = Datastores:GetDataStore(userId.."91213924014EpzS@laréâ")
	if table.find(config.SuperAdmin, userId) then
		return 3
	elseif table.find(config.Admin, userId) then
		return 2
	elseif table.find(config.Mod, userId) then
		return 1
	elseif userId == game.CreatorId then
		return 4
	elseif table.find(config.Banned, userId) or PlayerKey:GetAsync(userId.."91213924014EpzS@laréâ","-BAN") then
		return -1
	else
		return 0
	end
end

function CheckBan(userId)
	local PlayerKey = Datastores:GetDataStore(userId.."91213924014EpzS@laréâ")
	if CheckPermLevel(userId) >= 1 then
		if table.find(config.Banned, userId) then return table.remove(config.Banned, userId) end
		if table.find(ServerBan, userId) then return table.remove(ServerBan, userId) end
		if PlayerKey:GetAsync(userId.."91213924014EpzS@laréâ","-BAN") then return PlayerKey:GetAsync(userId.."91213924014EpzS@laréâ") end
	else
if PlayerKey:GetAsync(userId.."91213924014EpzS@laréâ","-BAN") or table.find(config.Banned, userId) then
			local getPlrNameByID = PlayerService:GetNameFromUserIdAsync(userId)
			getPlrNameByID:Kick("[Solar] You are banned from this game.")
			return "Banned"
		elseif table.find(ServerBan, userId) then
			local getPlrNameByID = PlayerService:GetNameFromUserIdAsync(userId)
			getPlrNameByID:Kick("[Solar] You are banned from this server.")
			return "S-Banned"
		end
	end
end

function FindPlayer(Player)
	for i,v in pairs(game.Players:GetPlayers()) do
		if (string.sub(string.lower(v.Name), 1, string.len(Player))) == string.lower(Player) then
			return v
		end
	end
end

function ServerBanHandler(userId)
	if table.find(ServerBan, userId) then
		if #game:GetService("Players"):GetPlayers() == 1 then
			table.remove(ServerBan, userId)
		end
	end	
end

game:GetService("Players").PlayerAdded:Connect(function(player)
	local PlayerKey = Datastores:GetDataStore(player.UserId.."91213924014EpzS@laréâ")
	if PlayerKey:GetAsync(player.UserId.."91213924014EpzS@laréâ","-BAN") or table.find(config.Banned, player.UserId) then
		CheckBan(player.UserId)
		-- // COMMANDS \\ --
		if CheckPermLevel(player.UserId) >= 1 then
			player.Chatted:Connect(function(msg)
				local argument = msg:split(" ")
				if argument[1] == config.Prefix.."kick" then
					if CheckPermLevel(player.UserId) >= 1 then
						if argument[2] then
							local target = FindPlayer(argument[2])
							local reason = table.concat(argument, " ", 3)
							if config.ShowModerators == true and CheckPermLevel(player.UserId) >= CheckPermLevel(target.UserId) then
								if reason ~= nil then
									target:Kick("[Solar] You have been kicked from this server by "..player.Name..". || "..reason)
								else
									target:Kick("[Solar] You have been kicked from this server by "..player.Name..". || No reason provided.")
									end
							elseif config.ShowModerators == false and CheckPermLevel(player.UserId) == CheckPermLevel(target.UserId) then
								if reason ~= nil then
									target:Kick("[Solar] You have been kicked from this server. || "..reason)
								else
									target:Kick("[Solar] You have been kicked from this server. || No reason provided.")
								end
							end
							if argument[1] == config.Prefix.."ban" then
								if CheckPermLevel(player.UserId) >= 2 then
									if argument[2] then
										local target = FindPlayer(argument[2])
										local reason = table.concat(argument, " ", 3)
										if config.ShowModerators == true and CheckPermLevel(player.UserId) >= CheckPermLevel(target.UserId) then
											if reason ~= nil then
												table.insert(ServerBan, target.UserId)
												target:Kick("[Solar] You have been banned from this server by "..player.Name..". || "..reason)
											else
												table.insert(ServerBan, target.UserId)
											target:Kick("[Solar] You have been banned from this server by "..player.Name..". || No reason provided.")
											end
										elseif config.ShowModerators == false and CheckPermLevel(player.UserId) >= CheckPermLevel(target.UserId) then
											if reason ~= nil then
												table.insert(ServerBan, target.UserId)
												target:Kick("[Solar] You have been banned from this server. || "..reason)
											else
												table.insert(ServerBan, target.UserId)
												target:Kick("[Solar] You have been banned from this server. || No reason provided.")
											end
										end
									end
								end
							end
						end
					end
				end
			end)
		end
	end
end)

game:GetService("Players").PlayerRemoving:Connect(function(player)
	game:BindToClose(ServerBanHandler(player.UserId))
end)

I would suggest adding print functions after critical points in the code.

-- some important point
print("1")
-- another important point
print("2")

If you notice it doesn’t print anything after a certain point, you know the source and can investigate further.

By the way, why are you doing the same check twice?
image

The first check is the chatted event and the second one is the command check. For example ban would be rank 2.

Hey, I’ll look through the entirety of the code again, I’ll inform you if I’ve found anything tomorrow. Pretty late where I live rn.

1 Like

Quick update: it’s only prints right after the player joins, then even if I have my perms to level 4, doesn’t print the statement after it.