How to assign findfirstchild to a different child

Hello I would like to know how to change the child of findfirstchild, like just say inside a folder I have 3 Values named “Hi” each and I add a value in each of them called taken. and It will do the findfirstchild and check, if the value is taken then it will run findfirstchild until it find the one that isnt taken.

Sorry if its hard to understand

Just use the ‘found child’ and run findfirstchild on that. ??

Since you have more than one child with the same name you’ll need to use getchildren instead though. then cycle through those with findfirstchild till you find the one you want to use

I dont understand can you explain

how could I change

local pet3 = script.Parent.Container:FindFirstChild(name, true) 

to a get children

for _, child in ipairs(script.Parent.Container) do
     if child:findfirstchild(searchterm) then
        --do something
     end
end

plug in your own item for searchterm, whatever child you’re trying to match

would I change search term to name, true

You could, but your child should be on the next level so you wouldn’t need to recurse. Maybe just substitute (name)

actually you’d have to check the value of each child so you have more work to do

Ok ill try it and see if it will work

Youll have to check the value of the ‘taken’ bool or string value so you have more you need in that loop

for _, pet3 in ipairs(script.Parent.Container) do
	if pet3:FindFirstChild(split3[2]) then
		pet3.EquipBestTaken.Value = true
		if pet3.EquipBestTaken.Value == true then --check
			print(pet3.Name.." IS TAKEN")
		end
		print(pet3.Name)
		pet3.Equipped.Value = true
		replicatedStorage.EggHatchingRemotes.EquipPet:InvokeServer(split3[2])
		pet3.Checkmark.Visible = true
	end
end

I’m a little confused by your request, but this should help you:

local found = nil

for _,child in pairs(script.Parent.Container:GetChildren()) do
  if not child.taken.Value then
    found = child
    break
  end
end

print(found:GetFullName())
-- ...