You can use a name, but I want to use a function on the candidate.
For my case, I want it not to be of name, but any name with the name containing keyphrase “door”. Which I know how to do with find, just not on an iterating upward ancestral chain fashion.
The second case being a function that looks to see if the candidate ancestor is the one to first contain a specific descendant, or have descendant(s) of the required specifics and attributes.
Just loop through the Parents and run the function.
local function findFirstAncestor(descendant, callback)
while not callback(descendant) do
if descendant == game then return nil end
descendant = descendant.Parent
end
return descendant
end
Alternatively, you could try parsing the string returned by GetFullName for this specific case:
local fullName = whatever:GetFullName()
local ancestorName = string.match(fullName, "%.([^%.]*door[^%.]*)%.")
local ancestor = whatever:FindFirstAncestor(ancestorName)