Two objects in :IsA () with a table?

Hi, I have a quick question, is it possible to use a table with 2 different objects to know if an object is a folder or a model?

Or do I have to use IsA () twice?

Here I leave a script for you to understand better what I mean

local A = {
	"Model";
	"Folder";
}

local ServerStorage = game.ServerStorage:GetChildren()

for i, v in pairs(ServerStorage) do
	if v:IsA(#A) then
		print("Yes?") --Prints yes if an object is a folder or a Model
		
	else
		print("No")
	end
end

I think it would be easier to use “ClassName” but I just want to know if it can be done with IsA ()

If there is any other way could you explain why IsA () does not work with the table please :b

local ServerStorage = game.ServerStorage:GetChildren()

for _, Child in pairs(ServerStorage) do
	if Child:IsA("Folder") or Child:IsA("Model") then
		print("Yes?") --Prints yes if an object is a folder or a Model
	else
		print("No")
	end
end

try this

local ServerStorage = game.ServerStorage:GetChildren()

for _, Child in pairs(ServerStorage) do
	if table.find({"Folder", "Model"}, Child.ClassName) then
		print("Yes?") --Prints yes if an object is a folder or a Model
	else
		print("No")
	end
end

this is another option you could try

local ServerStorage = game.ServerStorage:GetChildren()

local ClassNameTable = {
	"Model",
	"Folder"
}

for _, item in pairs(ServerStorage) do
	for _, itemType in pairs(ClassNameTable) do
		
		if item:IsA(itemType) then
			print("Yes")
		else
			warn("No")
		end
		
	end
	
end

I would more do this if you want to be able to add more types to a certain table. Or you could use table.find() in order to see if it is part of the table already.

2 Likes

actually I’m wrong, again devforum fix the delete post bug

it’s annoying

Not sure why we need nested loops for a simple problem, time complexity is being increased for no reason when it can be done in O(n) as suggested by D0RYU in their first reply.

:IsA() works differently to how simply reading the ClassName works. :IsA() respects inheritance while ClassName does not. For example, if you used @D0RYU’s code with BasePart and the object it was inspecting was a Part, it would print “No”. @Xronixle’s code would work best in this situation if the OP was looking for usage identical to the :IsA() function.

2 Likes

this would only print “no” in the second piece of code I gave