Hey, there are 4 ways to do this.
EDIT: I found out about "AncestryChanged" which is the perfect solution (Thanks Aleph)
The first return of the event is the instance that had its parent changed, so in this case 'object' and the second one is the new parent.
object.AncestryChanged:Connect(function(_, newParent)
print("Parent has been changed")
end)
--
First would be to use GetPropertyChangedSignal("Parent")
local p = Instance.new('Part')
p:GetPropertyChangedSignal('Parent'):Connect(function()
print("The parent has been changed")
end)
or .Changed and check if the property is "Parent"
p.Changed:Connect(function(property)
if property == "Parent" then
print("parent changed")
end
end)
You can also use .ChildRemoved on the object's parent and check if the object that got removed is the one you know.
local obj = workspace.Object
workspace.ChildRemoved:Connect(function(object)
if object == obj then
print("parent has been changed")
end
end)
2 comments
Does the part already have a parent?
You could set a variable equal to the current parent and use a while loop to check if it's changed?