AncestryChanged

Constructor:

AncestryChanged(AncestryChanged)

Description

Triggered when the ancestry is changed.

Parameters

Name Type Description
AncestryChanged RWObject The parent object after changed

Examples

Create a three-hierarchy structure and the third hierarchy is part object. Change the part color when its ancestry changes, and output the parent object name.

local folder = RWObject.Create("Folder") -- create folder1
folder.Parent = WorkSpace
local folder2 = RWObject.Create("Folder") -- create folder2
folder2.Parent = folder
local part = RWObject.Create("Part") -- create a part object
part.Position = Vector3.New(1,2,1)
part.Parent = folder2 -- set the part object as the child of folder2
part.AncestryChanged:Connect(function(ancestrychanged) -- triggered when a child object is added into the folder
    part.Color = Vector3.New(255,0,0)
    print(ancestrychanged.Name)
end)
wait(3)
part.Parent = WorkSpace -- move the part object from folder2 to WorkSpace.