How do I get only descendants of a certain type?

Title says everything
Here’s what I’ve currently got

-- Module script in ReplicatedStorage (not the entire thing)
function Utility:GetDescendantsOfClass(Parent, Type)
	local Table = {}

	for _, Object in ipairs(Parent:GetDescendants()) do
		if Object:IsA(Type) then
			table.insert(Table, Object)
		end
	end

	return Table
end
-- Call from localscript
print(Utility:GetDescendantsOfClass(parent, "Part"))

For some reason when I call the function, it returns all descendants and not just parts
Did I mess something up? Should I not have it in a module script?

2 Likes

Note that most of both scripts are removed
Everything is defined correctly which I’ve confirmed with another function that works correctly

Try checking if the values that you are receiving from the remote call are correct by displaying them in your console via the print() command;

print(Parent) 
print(Type) 

Turns out I was interpreting the result wrong

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.