Why is this script still returning true?

Im making a plugin to scan for malicious scripts and want to exclude CoreGui because it fills up the entire list. But this is still running? Why is it doing this?

for i, d in pairs(obj:GetDescendants()) do
			if not d:IsDescendantOf(game.CoreGui) and d:IsA("Script") or d:IsA("LocalScript") or d:IsA("ModuleScript") then
				print(d:IsDescendantOf(game.CoreGui))
				--Code bla bla bla
			end
		end

And here is the output
image

It should be all false but its still returning some true?

1 Like

image
Thanks for helping though!

Try doing this:

if not d:IsDescendantOf(game.CoreGui) and (d:IsA("Script") or d:IsA("LocalScript") or d:IsA("ModuleScript")) then
1 Like

Thank you :pray: It works perfectly!

Yeah, you just needed to wrap the first part of the conditional statement inside a pair of parentheses, that way the Boolean logic operator “not” is not influencing the entire conditional statement but only the first component of it. Conversely you could have also done:

for i, d in pairs(obj:GetDescendants()) do
	if d:IsA("Script") or d:IsA("LocalScript") or d:IsA("ModuleScript") and not d:IsDescendantOf(game.CoreGui) then
		print(d:IsDescendantOf(game.CoreGui))
		--Code bla bla bla
	end
end