How to ignore certain items when using FindFirstChildOfClass()

I’m sure this has been asked before, I just cant find it anywhere. So I pretty much just need to know how you would ignore certain items when using FindFirstChildOfClass(), this is incase multiple thing sare of the same class. I can’t use FindFirstChild() in this situation unfortunately, which is why I’m asking.

Im not sure what you are asking, can you explain a bit more?

Assuming you dont know the Variables:


FindFirstChild() looks for an Item under a Certain Name

WaitForChild() looks for an Item for a certain time period before timing out

FindFirstChildOfClass() Simply looks for an Item under a certain class.

FindFirstChildWhichIsA() Is Similar to FindFirstChildOfClass(), not sure of the difference

IsA() Checks if a Part Is A certain Instance (Class)

1 Like

The main problem I’m having is in my situation I can not use FindFirstChild() because the player choses the thing so I cant assume what the name of the item will be. However, I know what it cant be so I can narrow it down if I know how to ignore items but I’m lost on how to do that.

You can make it, for each object, check all objects

local function FindOfChildCustom(Parent: Instance, Descendants: boolean, ToCheck: (Objec: Instance) -> boolean?)
	for _, v in pairs(if Descendants then Parent:GetDescendants() else Parent:GetChildren()) do
		local Break = ToCheck(v)
		if Break then		return v		end
	end
end

--		Example		--
local Find = FindOfChildCustom(workspace, true, function(Obj)
	if Obj:IsA("Part") and Obj.Name:gmatch("Me") then
		return true
	end
end)
warn(Find)

In the requested function, check what that object needs, if you need it, return true so that the loop stops.

Well I know the name of the items to ignore, so is there a way I can put them into a string or variable or something to ignore during the findfirstchildofclass?

local Items = {}
local Children = Your Items:GetChildren()
table.insert(Items, Children)

if not table.find(Items, Children) then -- Checks if the Item is not inside the Table
end

If the player is picking the item that they want, then you can easily store that information to be able to search for it during runtime.

1 Like

With the function I gave, check it

local Ignore = {"testing"}
local Parent = workspace
local Find = FindOfChildCustom(Parent, true, function(Obj)
	return Obj:IsA(Class) and not table.find(Ignore, Obj.Name)
end)
warn(Find)

add what you will ignore to Ignore and replace Class

Oh I see… let me see what I can do with all this, I’ll get back you you and the others
ty

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