Soo question is in title, here is code:
local Vaccumulator = {}
Vaccumulator.__index = Vaccumulator
function Vaccumulator.new(IsOneTimeUse: boolean): {}
local self = setmetatable({}, Vaccumulator)
self.List = {}
self.IsOneTimeUse = IsOneTimeUse
self.HighestIndex = 0
return self
end
----[[PRIVATE]]----
local function ClearTable(Table: {})
setmetatable(Table, nil)
for _, object in Table do
if typeof(object) == "table" then ClearTable(object); Table[_] = nil; continue end
if typeof(object) == "thread" then task.cancel(object); continue end
if typeof(object) == "RBXScriptConnection" then object:Disconnect(); continue end
if typeof(object) == "Instance" then object:Destroy(); continue end
Table[_] = nil
end
end
----[[PUBLIC]]----
-- add new class to a CleanUp list
function Vaccumulator:Add(Class: {}, mode: string): number
table.insert(self.List, Class)
self.HighestIndex += 1
return self.HighestIndex
end
-- remove specific class from CleanUp list
function Vaccumulator:Remove(index: number)
table.clear(self.List[index])
table.remove(self.List, index)
self.HighestIndex -= 1
end
-- clear specific class from CleanUp list
function Vaccumulator:ClearClass(index: number, Mode: (any) -> (), ...)
local ClassToClear = self.List[index]
if Mode then
Mode(ClassToClear, ...) --/ custom clean up function
else
ClearTable(ClassToClear)
end
self:Remove(index)
end
-- clear all classes from CleanUp list
function Vaccumulator:ClearAll()
for _ = 1, self.HighestIndex do
self:ClearClass(self.HighestIndex)
end
end
-- destroy vaccumulator
function Vaccumulator:Destroy(CleanupBeforeDestroying: boolean)
if CleanupBeforeDestroying then self:ClearAll() end
self.List = nil
self.IsOneTimeUse = nil
self.HighestIndex = nil
setmetatable(self, nil)
table.freeze(self)
end
return Vaccumulator
Note: I wanted to make something myself that will help me, i really don’t like using public modules as i fell they can’t do what i want