Ban doesn't work, no errors

The title is self explanatory, my ban command won’t work.

local Datastore = game:GetService("DataStoreService")
local BanDatastore = Datastore:GetDataStore("Ukip18414194180149915015910150151")
local Settings = require(game:GetService("ServerScriptService").ModerationPackageV1.Modules.Settings)
local PlrService = game:GetService("Players")

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

game.Players.PlayerAdded:Connect(function(plr)
	if BanDatastore:GetAsync(plr.UserId,true) and not table.find(Settings.Admins, plr.UserId) then
		plr:Kick("You are banned")
	else
		if table.find(Settings.Admins, plr.UserId) then
			plr.Chatted:Connect(function(msg)
				local arg = msg:split(" ")
				if string.lower(msg) == Settings.prefix.."ban" then
					if arg[2] then
						local target = GetPlayer(arg[2])
						local ID = target.UserId
						if table.find(Settings.Admins, ID) then return warn("Cannot ban a admin") end
						local Success, ErrorMessage = pcall(function()
							BanDatastore:SetAsync(ID,true)
						end)
						if Success then
							target:Kick("The ban hammer has spoken!")
						else
							error(ErrorMessage)
						end
					end
				end
			end)
		end
        end
end)
if string.lower(msg) == Settings.prefix.."ban" then

You’re checking against the entire msg, not but you want to check for the command name, try this.

if string.lower(arg[1]) == Settings.prefix.."ban" then

You should add a error for “no command found!” as this if’s else clause.

2 Likes

Hey, the change worked. Thanks for your help.