GetAncestorByName

Constructor:

GetAncestorByName(Name)

Description

Returns the first parent with the given name. This function searches upwards, which means it searches upwards from the direct parent of the object. If the matching parent node cannot be found, the function returns nil.

Parameters

Variable name Type Default Description
Name string Name of parent node to seek

Return Value

Type Description
RWObject Parent object to seek. If no matching object, return nil.

Examples

Create a three-hierarchy structure, and seek the specified parent upwards from the child object of the 3rd hierarchy.

local part1 = RWObject.Create("Model") -- create a model named N1
part1.Name = "N1"
part1.Parent = WorkSpace
local part2 = RWObject.Create("Model") -- create a model named N2, and set its parent as N1
part2.Name = "N2"
part2.Parent = part1
local part3 = RWObject.Create("Part") -- create a Part named N3, and set its parent as N2
part3.Name = "N3"
part3.Position = Vector3.New(3,2,3) -- set the coordinates of N3
part3.Anchored = true -- anchor N3
part3.Parent = part2
local part4 = part3:GetAncestorByName("N1") -- retrieve the first parent named N1 of N3, change its name to ChangeN1, and change the color of N3 into red
part4.Name = "ChangeN1"
part3.Color = Vector3.New(255,0,0)