Anti Virus Detecting Items Already Contained

So, I am making a anti virus plugin called “Shield Anti Virus” and when I scan through the objects I make sure that there parent is not the folder I hold the viruses in but it still prints in the output that they have been detected.

while wait(scanDelay) do
	for num, obj in pairs(game:GetDescendants()) do
		for i,v in pairs(names) do
			pcall(function()
				if string.lower(obj.Name) == string.lower(v) and not(obj == script) then
					if game:GetService("ServerStorage"):FindFirstChild(folderName) and obj.Parent ~= game:GetService("ServerStorage"):FindFirstChild(folderName) then
						print("--<<Shield Anti-Virus>>--\nFound: " .. obj.Name)
						contain(obj)
						table.insert(viruses, obj)
					end
				end
			end)
		end
		wait()
	end
end

I don’t know, I have been debugging and stuff so I might just be missing something obvious. NOTE: This is not the entire script I tried only showing what I thought I need to show because I am paranoid but, if you need more I can update it to include more of the script. :smile:

You can check if obj.Parent is equal to the folder you have it in. Just be sure the folder containing your virus names only goes down 1 level and not any further (otherwise the name of the Parent is something different). You’re going to need to show us how you’re defining your variables. In theory, your script should work but it doesn’t either because you’re running an outdated version or folderName is defined to something not intended.

Perhaps you could use IsDescendantOf to check if obj:IsDescendantOf(PathToYourFolder).

1 Like

I think your solution worked. It did detect one of the “viruses” 3 times but other than that it stopped detecting them over and over. And this is going to be a plugin which will just run every two minutes or so in the background to try to catch any sneaky viruses. It does not detect the actual source code. I think it could be it’s looping to much (I have it looping ever 2 seconds for testing.) so it’s lagging. Either way it will work. Although I think it will be cool to add a require and loadstring checks and stuff as well. But, thank you all for your help! :smiley:
EDIT: It was running still while I typed this and it was still detecting it over and over. I might fix it but the problem isn’t the end of the world… Here it the script in case I’m missing something…

while wait(scanDelay) do
	for num, obj in pairs(game:GetDescendants()) do
		for i,v in pairs(names) do
			pcall(function()
				if string.lower(obj.Name) == string.lower(v) and not(obj == script) then
					if folder and obj:IsDescendantOf(folder) == false then
						contain(obj)
						table.insert(viruses, obj)
					elseif not folder then
						local new = Instance.new("Folder")
						new.Name = folderName
						new.Parent = game:GetService("ServerStorage")
						contain(obj)
						table.insert(viruses, obj)
						folder = new
					end
				end
			end)
		end
		wait()
	end
end