Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How does :FindFirstAncestor() find the first ancestor?

Asked by 3 years ago

https://developer.roblox.com/en-us/api-reference/function/Instance/FindFirstAncestor

So I wanted to know how "FindFirstAncestor" works because I want to modify it for my personal needs. I already know how to use the function, but I want to know how it's source code works. It's source code isn't posted anywhere. How does it find the first ancestor?

1 answer

Log in to vote
0
Answered by
A_Mp5 222 Moderation Voter
3 years ago

I don't know but this is my guess. This is hardly tested and is very messy, and likely won't work but this is my basic idea.

local function findAncestor(object,name)
    local Parents = {}
    local Index = object
    local Done = false
    repeat
        table.insert(Parents,Index.Parent)


            print(Index)
        if Index.Parent.Name == name then
            Done = true
        elseif Index == game then
            Done = true
        end

        Index = Index.Parent
    until Done == true
    return Index
end

findAncestor(PartExample, "NameExample") -- Example
Ad

Answer this question