How to find first child with a specific string

I want to be able to find first child with a specific string in a parts name. For example

Green Part
Blue Part
Purple Part
Pink Part
etc....

And I want to use find first child to basically see if a specific ‘part’ exists. I know of string.find but I don’t believe that’d work in this cause.

PLEASE NOTE!! I am not just gonna do

if Model:FindFirstChild('Green Part') then

end

if Model:FindFirstChild('Blue Part') then

end

-- etc.

This is a more broader question. Imagine if I had 200 different variants. I just wanna be able to check if a specific item exists in a model, with a specific name

I can’t understand, please explain again.

I have a model. If that model can only have 1 part with a specific name it, I wanna be able to find it, so I can remove it. Let’s say that part is called ‘Green Part’ then I wanna find it, and then remove it. I can’t just do FindFirstChild(‘Green Part’) as it could be ‘Blue Part’ or ‘Red Part’

I basically wanna find the first item with the string ‘Part’ in it

Not sure if I understand your question but what you need to do is make a table

local Table = {}

and put all of the name in there

local Table = {"Test1", "Test2", "Test3"}

now added a line in which it will find if part’s name exist in the table

for _,Part in pairs(Model:GetChildren()) do
     if table.find(Table, Part.Name) then
        print("Part found")
    end
end

Screen Shot 2563-05-16 at 19.16.57

Output:
-->> "Part Found"

2 Likes

If you want the found part to be remove then just simply add Part:Destroy()

for _,Part in pairs(Model:GetChildren()) do
         if table.find(Table, Part.Name) then
            print(Part.Name)
            Part:Destroy()
        end
    end