Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/corecii/roblox-instancedestroyed

Detects when an Instance will never re-appear in the game tree. Fires on Destroy and garbage-collection.
https://github.com/corecii/roblox-instancedestroyed

Last synced: 12 days ago
JSON representation

Detects when an Instance will never re-appear in the game tree. Fires on Destroy and garbage-collection.

Awesome Lists containing this project

README

        

# Documentation
This module can be used to detect when an instance is destroyed at any point after it is used on the object.
It will detect when the object is `Destroy`ed from the game hierarchy, when it is `Destroy`ed from nil, and when it is garbage-collected.
The call returns a pseudo-signal which can be used to check if the function is connected and can be used to disconnect the on-destroy-function without causing it to fire.


* pseudoSignal module(Instance instance, function func)
Attach the function 'func' to be called when the Instance 'instance' is destroyed

* pseudoSignal
* boolean .connected, .Connected
If the function provided is still connected then this is true. When the object is destroyed this is set to false before the function is called.
This can only be false if the object is destroyed or if this is manually disconnected.

* void :disconnect(), :Disconnect()
Manually disconnects the connected function before the object is destroyed.

* RBXScriptSignal .connection
This is the actual connection to the instance's AncestryChanged event. This should not be messed with.

# Changes pre-git-repo
* Edit 5:
Clarify comments on coroutine.yield because behavior has changed from [end of current execution cycle] to [beginning of next execution cycle]
* Version 4:
Fixed garbage collection detection.
* Edit 3:
Clarified/fixed some terminology. (comments only)
* Version 2:
Made it not prevent garbage collection by using ObjectValues
* Version 1:
Initial

See original Gist for diffs: https://gist.github.com/Corecii/2c86fb338802a618e3ff376d61409b1b