How can I search for objects by name with GetChildren?

Well, I want you to be able to search for objects by their name with GetChildren so that if they have a defined name, the function is done with the objects that have that name, for example:

local Model = game.Workspace.Folder:GetChildren()

        for i, child in ipairs(Model) do
         if child:IsA("BasePart") then
          child:WaitForChild("Model"):WaitForChild("Part").Material = Enum.Material.Wood
       end
end

In this I put that all the children called “Part”, change the subject to wood, but it does not work

1 Like

An easy way to do it is to union the parts together, which would make it only one part, and you can use the same script you have already written.

Are you trying to make a search bar?

You could simply compare the Child’s Name property and run some code depending on the results. Here’s what it would look like:

local Model = game.Workspace.Folder:GetChildren()

for i, child in ipairs(Model) do
	if child:IsA("BasePart") and child.Name == "Part" then -- Change "Part" to the name which will trigger the line below
		child:WaitForChild("Model"):WaitForChild("Part").Material = Enum.Material.Wood
	end
end
1 Like

eh, it doesn’t work for me nor does it give any error when executing it

Another possible issue could be child:IsA("BasePart"). Try removing that and check if it works, you might get different results if you are looking to change objects which are not of that class.

1 Like