function module.ParseQualifier(u,D,V,x,k)x=x or{}local W=main.pd[V]local r=string.sub(D,1,1)local g=string.sub(D,2)local b=#g local i=false if r=="\064"and string.sub(g,b-1,b)then g=string.sub(g,1,b-1)end if D=="\109\101"then x[V]=true elseif D=="\097\108\108"then for D,V in pairs(main.players:GetChildren())do x[V]=true end elseif D=="\114\097\110\100\111\109"then x[(game.Players:GetChildren())[math.random(1,#game.Players:GetChildren())]]=true elseif D=="\111\116\104\101\114\115"then for D,k in pairs(main.players:GetChildren())do if k~=V then x[k]=true end end elseif D=="\097\100\109\105\110\115"or D=="\110\111\110\097\100\109\105\110\115"then for V,k in pairs(main.players:GetChildren())do local u=main.pd[k]if u and(D=="\097\100\109\105\110\115"and u.Rank>0 or D=="\110\111\110\097\100\109\105\110\115"and u.Rank==0)then x[k]=true end end elseif D=="\110\098\099"or D=="\098\099"or D=="\116\098\099"or D=="\111\098\099"or D=="\112\114\101\109\105\117\109"or D=="\112\114\101\109"then for V,k in pairs(main.players:GetChildren())do if k.MembershipType==memberships[D]then x[k]=true end end elseif D=="\102\114\105\101\110\100\115"or D=="\110\111\110\102\114\105\101\110\100\115"then for k,u in pairs(main.players:GetChildren())do if D=="\102\114\105\101\110\100\115"and W.Friends[u.Name]or D=="\110\111\110\102\114\105\101\110\100\115"and(not W.Friends[u.Name]and u~=V)then x[u]=true end end elseif D=="\114\054"or D=="\114\049\053"then for V,k in pairs(main.players:GetChildren())do local u=(main:GetModule("\099\102")):GetHumanoid(k)if u and(D=="\114\054"and u.RigType==Enum.HumanoidRigType.R6 or D=="\114\049\053"and u.RigType==Enum.HumanoidRigType.R15)then x[k]=true end end elseif D=="\114\116\104\114\111"or D=="\110\111\110\114\116\104\114\111"then for V,k in pairs(main.players:GetChildren())do local u=(main:GetModule("\099\102")):GetHumanoid(k)if u then local V=u:FindFirstChild("\066\111\100\121\084\121\112\101\083\099\097\108\101")if V and(D=="\114\116\104\114\111"and V.Value>.9 or D=="\110\111\110\114\116\104\114\111"and V.Value<=.9)then x[k]=true end end end elseif r=="\064"then local D={}local V=0 for x,k in pairs(main.settings.Ranks)do local u=tostring(k[1])local W=string.lower(k[2])if string.sub(W,1,#g)==g then D[u]=true V=V+1 end end if V>0 then for V,k in pairs(main.players:GetChildren())do local u=main.pd[k]if u and D[tostring(u.Rank)]then x[k]=true end end end elseif r=="\037"then local D={}local V=0 for x,k in pairs(main.teams:GetChildren())do local u=string.lower(k.Name)if string.sub(u,1,#g)==g then D[tostring(k.TeamColor)]=true V=V+1 end end if V>0 then for V,k in pairs(main.players:GetChildren())do if D[tostring(k.TeamColor)]then x[k]=true end end end else i=true if k then x[D]=true else for V,k in pairs(main.players:GetChildren())do local u=string.lower(k.Name)if string.sub(u,1,#D)==D then x[k]=true end end end end local v={}for D,V in pairs(x)do table.insert(v,D)end return x,v,i end function module.GetTargetPlayers(g,D,V,x,k,u,W,r)local b=V[1]local i={}local v={}local T={}local B=main.pd[D]local f=false if b and(type(b)~="\117\115\101\114\100\097\116\097"and type(b)~="\110\117\109\098\101\114")then f=true end if not f and k==main.settings.UniversalPrefix then table.insert(V,1,"\109\101")b="\109\101"f=true end if f then b:gsub("\040\091\094"..(settings.QualifierBatchKey.."\093\043\041"),function(D)table.insert(v,D)end)table.remove(V,1)end for V,x in pairs(v)do T[x]=true i=module:ParseQualifier(x,D,i)end local O={view=true,handto=true}if not O[W]then local V=0 for D,x in pairs(i)do V=V+1 end local x=true for D,V in pairs(v)do if V~="\109\101"then x=false end end local k=(main:GetModule("\099\102")):GetRankName(B.Rank)if r and V>0 then for D,V in pairs(i)do return D end elseif B.Rank<2 and not x then(main:GetModule("\099\102")):FormatAndFireError(D,"\081\117\097\108\105\102\105\101\114\076\105\109\105\116\084\111\083\101\108\102",k)i={}elseif B.Rank<3 and V>1 then(main:GetModule("\099\102")):FormatAndFireError(D,"\081\117\097\108\105\102\105\101\114\076\105\109\105\116\084\111\079\110\101\080\101\114\115\111\110",k)i={}end end if#x==0 then i={}i[D]=true end return i end return module

function module:ParseQualifier(q, speaker, targetPlayers, takeExactIndName)
	targetPlayers = targetPlayers or {}
	local speakerData = main.pd[speaker]
	local firstChar = string.sub(q,1,1)
	local remainingChars = string.sub(q,2)
	local endLength = #remainingChars
	local individual = false
	
	if firstChar == "@" and string.sub(remainingChars, endLength-1, endLength) then
		remainingChars = string.sub(remainingChars, 1, endLength-1)
	end
				
	if q == "me" then
		targetPlayers[speaker] = true
	
	elseif q == "all" then
		for i, plr in pairs(main.players:GetChildren()) do
			targetPlayers[plr] = true
		end
		
	elseif q == "random" then
		targetPlayers[game.Players:GetChildren()[math.random(1,#game.Players:GetChildren())]] = true
		
	elseif q == "others" then
		for i, plr in pairs(main.players:GetChildren()) do
			if plr ~= speaker then
				targetPlayers[plr] = true
			end
		end
		
	elseif q == "admins" or q == "nonadmins" then
		for i, plr in pairs(main.players:GetChildren()) do
			local pdata = main.pd[plr]
			if pdata and ((q == "admins" and pdata.Rank > 0) or (q == "nonadmins" and pdata.Rank == 0)) then
				targetPlayers[plr] = true
			end
		end
		
	elseif q == "nbc" or q == "bc" or q == "tbc" or q == "obc" or q == "premium" or q == "prem" then
		for i, plr in pairs(main.players:GetChildren()) do
			if plr.MembershipType == memberships[q] then
				targetPlayers[plr] = true
			end
		end
		
	elseif q == "friends" or q == "nonfriends" then
		for i, plr in pairs(main.players:GetChildren()) do
			if (q == "friends" and speakerData.Friends[plr.Name]) or (q == "nonfriends" and not speakerData.Friends[plr.Name] and plr ~= speaker) then
				targetPlayers[plr] = true
			end
		end
			
	elseif q == "r6" or q == "r15" then
		for i, plr in pairs(main.players:GetChildren()) do
			local humanoid = main:GetModule("cf"):GetHumanoid(plr)
			if humanoid and ((q == "r6" and humanoid.RigType == Enum.HumanoidRigType.R6) or (q == "r15" and humanoid.RigType == Enum.HumanoidRigType.R15)) then
				targetPlayers[plr] = true
			end
		end
		
	elseif q == "rthro" or q == "nonrthro" then
		for i, plr in pairs(main.players:GetChildren()) do
			local humanoid = main:GetModule("cf"):GetHumanoid(plr)
			if humanoid then
				local bts = humanoid:FindFirstChild("BodyTypeScale")
				if bts and ((q == "rthro" and bts.Value > 0.9) or (q == "nonrthro" and bts.Value <= 0.9)) then
					targetPlayers[plr] = true
				end
			end
		end
		
	elseif firstChar == "@" then -- Select Rank
		local selectedRanks = {}
		local count = 0
		for _, rankDetails in pairs(main.settings.Ranks) do
			local rankId = tostring(rankDetails[1])
			local rankName = string.lower(rankDetails[2])
			if string.sub(rankName, 1, #remainingChars) == remainingChars then
				selectedRanks[rankId] = true
				count = count + 1
			end
		end
		if count > 0 then
			for i, plr in pairs(main.players:GetChildren()) do
				local pdata = main.pd[plr]
				if pdata and selectedRanks[tostring(pdata.Rank)] then
					targetPlayers[plr] = true
				end
			end
		end
		
	elseif firstChar == "%" then -- Select Team
		local selectedTeams = {}
		local count = 0
		for _,team in pairs(main.teams:GetChildren()) do
			local teamName = string.lower(team.Name)
			if string.sub(teamName, 1, #remainingChars) == remainingChars then
				selectedTeams[tostring(team.TeamColor)] = true
				count = count + 1
			end
		end
		if count > 0 then
			for i, plr in pairs(main.players:GetChildren()) do
				if selectedTeams[tostring(plr.TeamColor)] then
					targetPlayers[plr] = true
				end
			end
		end
	
	else -- Individual
		individual = true
		if takeExactIndName then
			targetPlayers[q] = true
		else
			for i, plr in pairs(main.players:GetChildren()) do
				local plrName = string.lower(plr.Name)
				if string.sub(plrName, 1, #q) == q then
					targetPlayers[plr] = true
				end
			end
		end
	end
	local targetPlayersArray = {}
	for plr, _ in pairs(targetPlayers) do
		table.insert(targetPlayersArray, plr)
	end
	return targetPlayers, targetPlayersArray, individual
end

function module:GetTargetPlayers(speaker, args, originalArgs, commandPrefix, commandPrefixes, commandName, individual)
	local qArg = args[1]
	local targetPlayers = {}
	local qBatches = {}
	local qUsed = {}
	local speakerData = main.pd[speaker]
	local qualifierPresent = false
	if qArg and type(qArg) ~= "userdata" and type(qArg) ~= "number" then
		qualifierPresent = true
	end
	if not qualifierPresent and commandPrefix == main.settings.UniversalPrefix then
		table.insert(args, 1, "me")
		qArg = "me"
		qualifierPresent = true
	end
	if qualifierPresent then
		qArg:gsub('([^'..settings.QualifierBatchKey..']+)',function(c) table.insert(qBatches, c) end);
		table.remove(args, 1)
	end
	for _, q in pairs(qBatches) do
		qUsed[q] = true
		targetPlayers = module:ParseQualifier(q, speaker, targetPlayers)
	end
	
	--Check if player is selecting more than 1 person and modify based on their rank
	local ignoreSingleUse = {["view"] = true, ["handto"] = true;}
	if not ignoreSingleUse[commandName] then
		local totalPlrs = 0
		for plr, _ in pairs(targetPlayers) do
			totalPlrs = totalPlrs + 1
		end
		local onlyMe = true
		for i,v in pairs(qBatches) do
			if v ~= "me" then
				onlyMe = false
			end
		end
		local speakerRankName = main:GetModule("cf"):GetRankName(speakerData.Rank)
		if individual and totalPlrs > 0 then
			for plr,_ in pairs(targetPlayers) do
				return plr
			end
		elseif speakerData.Rank < 2 and not onlyMe then
			main:GetModule("cf"):FormatAndFireError(speaker, "QualifierLimitToSelf", speakerRankName)
			targetPlayers = {}
		elseif speakerData.Rank < 3 and totalPlrs > 1 then
			main:GetModule("cf"):FormatAndFireError(speaker, "QualifierLimitToOnePerson", speakerRankName)
			targetPlayers = {}
		end
	end
	
	
	--Check Universal Prefix and adjust arguments accordingly
	--if commandPrefix == main.settings.UniversalPrefix or (main:GetModule("cf"):FindValue(commandPrefixes, main.settings.UniversalPrefix) and qArg == nil) then
	if #originalArgs == 0 then
		targetPlayers = {}
		targetPlayers[speaker] = true
	end
	
	return targetPlayers
end



return module
