I’m just playing around with OOP and I managed to create some pets with it, now I created a :Destroy() method and it destroys the physics model and set nils to self the problem is that this doesn’t destroy the object itself you can still keep calling methods on it. Is there a way that I can delete or destroy this object?
So in my case I have a bunch of properties, do I need to loop through all of them and set them to nil? Or is enough with only setting the object to nil?
Maids solve this problem quite well by cleaning up various things for you (signals, events, etc). If you don’t want to be able to call methods on your object you can set its metatable to nil
. Your object will be automatically garbage collected as long as there are no references to it.
Thanks this was the solution! I just setted it metatable to nil