Event to detect when an instance is created

As a roblox developer it is currently impossible to detect when an instance is created. This would be a useful function in plugins when making tools that need to listen for new parts.

Currently, the only method to detect new items is .ChildAdded, however this fires for when instances are moved aswell as created.

game.ChildAdded:Connect(function(p)
  --oh no we're trying to identity check high identity stuff
end)

If Roblox are able to address this issue, it would allow us to create plugins that do something when an instance is created rather than having to rely on ChildAdded

6 Likes

This is a decent request, but it has very limited use and may cause performance issues if over 100 instances are created in a single frame with functions connected to the event.

As a temporary solution, you could make the plugin store all the instances in a table as indices and check whether an added instance already exists. It isn’t efficient, especially for large places, but it will do the job.

3 Likes

This is not as different as you think.

Moving something between two different parents in the game hierarchy is basically the same as deleting it and recreating it unless you have Lua scripts which are holding references to it. Many of the rendering and physics data structures associated with it in the backend must be recreated when you reparent it.

If you’re already “listening” on a particular object, you can listen for Instance::AncestryChanged which will fire when the parent or anything up the hierarchy from the instance is reparented. This gives some backdoor ways to know if something was created and not reparented.

But really you should re-evaluate whether you actually need to know that something was specifically created rather than moved.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.