Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I check the name of an object from values of a table?

So I'm creating a anti-virus scrip for my game and I want the script to compare the name of what it found to the values of the table

here's my script :

local destroyed = 0
local viruses={"Infected","Anti-Lag","Hack","Virus","Hidden","ROFL","4D Being","Guest Free Chat Script","Guest_Talking_Script"}	
local children = game.Workspace:GetChildren()
local children2 = game.Lighting:GetChildren()
local children3 = game.StarterPack:GetChildren()
local children4 = game.StarterGui:GetChildren()
local children5 = game.ServerStorage:GetChildren()
local children6 = children:GetChildren()

for num, child in ipairs( children ) do
  local inceptionChildren = child:GetChildren()
  for n, childOfChild in ipairs( inceptionChildren ) do
    if childOfChild.ClassName == "RotateP" then
		childOfChild:Destroy()
		destroyed = destroyed +1
	if childOfChild.Name == "Spread" then
		childOfChild:Destroy()
			destroyed = destroyed +1
	if childOfChild.Name == "Infected" then
		childOfChild:Destroy()
			destroyed = destroyed +1	
	if childOfChild.Name == "Infect" then
		childOfChild:Destroy()
			destroyed = destroyed +1
		if childOfChild.Name == "Vaccine" then
		childOfChild:Destroy()
			destroyed = destroyed +1
	if childOfChild.Name == "INFECT" then
		childOfChild:Destroy()
			destroyed = destroyed +1
		if childOfChild.Name == "Guest_Talk_Script" then
		childOfChild:Destroy()
			destroyed = destroyed +1
			  end
			end
		  end
		end
	  end
	end
  end
end
end

1 answer

✓ Accepted answer

I recommend using a recursive function to scan for potential viruses and running this in the command bar before you publish your game (no need to run it every time the game starts)

local destroyed = 0
local viruses={"Infected","Anti-Lag","Hack","Virus","Hidden","ROFL","4D Being","Guest Free Chat Script","Guest_Talking_Script"}

local function isVirus(partName)
	for _,virusName in next, viruses do
		if partName == virusName then
			return true
		end
	end
end

local function recursiveFunctionSearch(where)
	for _,obj in next, where:GetChildren() do
		if obj:IsA("Script") and isVirus(obj.Name) then -- We're calling the function we made above and putting the script's name inside so we can go through the entire viruses table and check if a value in there matches our script's name, if it is we assume it's a virus and this can pass and destroy the virus.
			obj:Destroy()
			destroyed = destroyed + 1
		end
		recursiveFunctionSearch(obj)
	end
end

recursiveFunctionSearch(workspace)
print("Destroyed",destroyed,"viruses")

http://wiki.roblox.com/index.php?title=Function http://wiki.roblox.com/index.php?title=Recursion

Hope this helps.

2 comments

0

thank you :)

0

You're welcome.

This discussion is preserved as it was. New answers, comments, and votes are closed.