How to destroy multiple objects at once?

I am trying to create a customize GUI and want to destroy every hair in the Player then equip the one selected but when I use this to do so:

		Character:GetChildren("LongBlack", "BrownFloof", "BrownCharmer"):Destroy()

		local ClonedHair = Hair:Clone()
		ClonedHair.Parent = Character
	end
end)

I get this error:

HairHandler:36: attempt to call a nil value

By the way, I am aware that separately destroying each hair would work but I want this to be efficient.

GetChildren doesn’t utilize any arguments. You’d want to use a loop and destroy the objects from there:

local names = {"LongBlack", "BrownFloof", "BrownCharmer"} -- name of the items
for _, object in ipairs(Character:GetChildren()) do -- loop through the children
   if table.find(names, object.Name) then
      -- use the object for something
   end
end
2 Likes