Yield script until child is removed

Pretty simple question, pretty simple answer I presume.

I want to yield (halt) the script until a child is removed from an instance.

What would I need to do to get this working?

Thankfully Roblox has something just for this. The ChildRemoved signal.

If you want to yield if any instance is removed, then you can do this.

local Container = ... --// reference to your container / instance

Container.ChildRemoved:Wait() --// Yields until any instance is removed from Container

If you want to yield until a specific instance is removed you can connect to AncestryChanged on the specific instance.

local Container = ...
local PartInsideContainer = Container.Part

PartInsideContainer.AncestryChanged:Wait()
3 Likes