We have :GetDescendants(), is there a way to do :GetAscendants()?

I think the title is very self-explanatory

I have this one script that’s just FILLED with horrifying elseif statements, i’d love to NOT have those elseif statements but there’s no way to do :GetAscendants()

GetAncestor() only gets the parent (or was it :FindFirstAncestor??())

does someone know some methods of doing that??? :pleading_face: :point_right: :point_left:

1 Like

you could get all ancestors of an instance like this

local function GetAncestors(x)
	local ancestors = {}
	while x.Parent ~= game do
		table.insert(ancestors,x.Parent)
		x = x.Parent
	end
	return ancestors
end
4 Likes

You can use :FindFirstAnscestor() if there is something specific you want to find.

For example: part:FindFirstAnscestor(nameOfAnyParent)

2 Likes