Im currently trying to find memory leaks in my game. Given I store quite a few things inside the player object I would need to know: When is it destroyed?
It’s obviously still there for some time to allow playerremoving to run, but how long until it’s completely GCed?
As with the nature of garbage collection, it is essentially random. Instances are destroyed when the garbage collector gets around to them, provided you have no lingering references to the Instances.
Destroying an object does not set Lua references to it to nil, this would make for very inconvenient programming if that were the case. As long as you have a reference to the Player object somewhere, it still exists because it is referenced.