Skip to content

Instantly share code, notes, and snippets.

@mvyasu
Last active February 17, 2024 19:28
Show Gist options
  • Select an option

  • Save mvyasu/ebea50d90a9ae47298db7b7d1c075887 to your computer and use it in GitHub Desktop.

Select an option

Save mvyasu/ebea50d90a9ae47298db7b7d1c075887 to your computer and use it in GitHub Desktop.
A simple cleanup function
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