So I've been thinking, does calling :Destroy() on a variable with a object reference make it turn nil? or is it gone forever.
For example:
local part = game.Workspace.Part part:Destroy() print(part.Name) --Does it result in nil or does it make the variable "part" non existent? (garbage colletion)
Thanks for viewing this!
While there is still a reference to the part, it will not be deleted by the garbage collector. All the Destroy() function does is it set's the instance's parent to nil and locks it to nil so it cannot be reassigned to another parent.
If you want it to be collected by the garbage collector, set the variable to "nil" and remove any other references to that part and the garbage collector will get to it.
local part = game.Workspace.Part part:Destroy() --//Locks parent to nil print(part.Name) --//You can still print the name because the object still exists, but it's parent is locked to nil part = nil --//Now that there is no reference to the part, the garbage collector will get it because there is no way to get the part ever again.
It results in it being non existent
https://developer.roblox.com/en-us/api-reference/function/Instance/Destroy