Last active
February 17, 2024 19:28
-
-
Save mvyasu/ebea50d90a9ae47298db7b7d1c075887 to your computer and use it in GitHub Desktop.
A simple cleanup function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| local function cleanupObject(object: any) | |
| local t = typeof(object) | |
| if t == "function" then | |
| object() | |
| elseif t == "RBXScriptConnection" then | |
| object:Disconnect() | |
| elseif t == "table" or t =="Instance" then | |
| if object.Destroy then | |
| object:Destroy() | |
| else | |
| local cleanupList = table.clone(object) | |
| table.clear(object) | |
| for _,child in cleanupList do | |
| cleanupObject(child) | |
| end | |
| end | |
| elseif t == "thread" then | |
| coroutine.close(object) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment