PcoWSkbVqDnWTu_dm2ix
The Developer Hub is now deprecated and information on this page may no longer be accurate. To see our new and improved documentation, please click here. You can read more about the future of documentation here.
Collapse Sidebar

FindFirstAncestorOfClass

Returns the first ancestor of the Instance whose Instance/ClassName is equal to the given className.

This function works upwards, meaning it starts at the Instance’s immediate Instance/Parent and works up towards the DataModel. If no matching ancestor is found, it returns nil.

A common use of this function is finding the Model a BasePart belongs to. For example:

local model = part:FindFirstAncestorOfClass("Model")

This function is a variant of Instance/FindFirstAncestor which checks the Instance/ClassName property rather than Instance/Name. Instance/FindFirstAncestorWhichIsA also exists, using the Instance/IsA method instead to respect class inheritance.

Parameters

Name Type Default Description

The Instance/ClassName to be looked for.

Returns

Return Type Summary

The Instance found.