AncestryChanged (Event): Difference between revisions
From Legacy Roblox Wiki
Jump to navigationJump to search
>NXTBoy No edit summary |
m Text replacement - "</SyntaxHighlight>" to "</syntaxhighlight>" |
||
(27 intermediate revisions by 7 users not shown) | |||
Line 1: | Line 1: | ||
<onlyinclude> | <onlyinclude>{{Event|name = AncestryChanged | ||
{{Event|name=AncestryChanged | |arguments = [[Instance]] <var>child</var>, [[Instance]] <var>parent</var> | ||
|arguments=[[Instance]] | |description = Fired when an ancestor of the Instance the event which is a member of <var>child</var> has its parent changed to <var>parent</var>. | ||
|description=Fired | |object = Instance | ||
|object=Instance | }}</onlyinclude> | ||
}} | |||
</ | {{clear floats}} | ||
{{Example|<syntaxhighlight lang="lua"> | |||
local p = Instance.new("Part") | |||
p.Parent = game.Workspace | |||
p.AncestryChanged:connect(function(child, parent) | |||
print(child.Name.." is now a child of "..parent.Name) | |||
end) | |||
p.Parent = game.Lighting --fires event | |||
</syntaxhighlight>}} | |||
==Notes== | |||
*<var>child</var> can be the object the event is a member of, or any of its ancestors. For example, if a [[Part]] is a child of a [[Model]] and the [[Model]]'s parent is changed to [[Lighting]], AncestryChanged would be fired on the [[Part]] with <var>child</var> being the [[Model]] and <var>parent</var> being [[Lighting]]. | |||
*<var>parent</var> can be {{nil}}. This event can be used to see when an Instance is removed from the game by testing if <var>parent</var> is {{nil}}. | |||
[[Category:Events]] | [[Category:Events]] |
Latest revision as of 05:19, 27 April 2023
AncestryChanged ( Instance child, Instance parent ) | |
Description | Fired when an ancestor of the Instance the event which is a member of child has its parent changed to parent. |
---|---|
Member of: | Instance |
Example
local p = Instance.new("Part")
p.Parent = game.Workspace
p.AncestryChanged:connect(function(child, parent)
print(child.Name.." is now a child of "..parent.Name)
end)
p.Parent = game.Lighting --fires event
Notes
- child can be the object the event is a member of, or any of its ancestors. For example, if a Part is a child of a Model and the Model's parent is changed to Lighting, AncestryChanged would be fired on the Part with child being the Model and parent being Lighting.
- parent can be nil. This event can be used to see when an Instance is removed from the game by testing if parent is nil.