Soo i have 3 libraries made by me few months ago:
Storing stuff across the server
local VACC = require(game:GetService("ReplicatedStorage").VACC)
local STORAGE = {
Dictionary = {},
Array = {}
}
function STORAGE:Add(value: any, group: string, index: string)
local mode = "Dictionary"
if not index then mode = "Array" end
local storageLocation = STORAGE[mode][group] or STORAGE[mode]
if mode == "Array" then table.insert(storageLocation, value) return end
storageLocation[index] = value
end
function STORAGE:Remove(value: any, group: string, isClearingEnabled: boolean, index: string)
local mode = "Dictionary"
if not index then mode = "Array" end
local storageLocation = STORAGE[mode][group] or STORAGE[mode]
if mode == "Array" then
local index = table.find(storageLocation, value)
if isClearingEnabled then VACC:Clear({storageLocation[index]}) end
table.remove(storageLocation, index)
return
end
if isClearingEnabled then VACC:Clear({storageLocation[index]}) end
storageLocation[index] = nil
end
function STORAGE:CreateGroup(group: string, mode: "Dictionary" | "Array")
if not STORAGE[mode] then return end
if STORAGE[mode][group] then return end
STORAGE[mode][group] = {}
return STORAGE[mode][group]
end
function STORAGE:RemoveGroup(group: string, mode: "Dictionary" | "Array", isClearingEnabled: boolean)
if not STORAGE[mode] then return end
if not STORAGE[mode][group] then return end
if isClearingEnabled then VACC:Clear(STORAGE[mode][group]) end
STORAGE[mode][group] = nil
end
return STORAGE
Maid/Cleanup class:
--==[[SELF]]==--
local VACC = {}
--==[[PUBLIC]]==--
-- set all indexes of given table to nil and calls special destroy/disconnect functions if object have them
function VACC:Clear(Object: {any})
for index, data in Object do
Object[index] = nil
if typeof(data) == "table" then self:Clear(data); continue end
if typeof(data) == "thread" then task.cancel(data); continue end
if typeof(data) == "RBXScriptConnection" then data:Disconnect(); continue end
if typeof(data) == "Instance" then data:Destroy(); continue end
end
setmetatable(Object, nil)
table.freeze(Object)
end
-- calls <Clear Table> function on every object inside given list
function VACC:CleanUp(Objects: {{any}})
for _, Object in Objects do
self:Clear(Object)
Objects[_] = nil
end
table.freeze(Objects)
end
return VACC
Events connection:
--==[[SELF]]==--
local EVENTS = {}
--==[[PRIVATE]]==--
local EventGroups = {}
--==[[PUBLIC]]==--
-- returns RBXScriptConnection depending on which mode was chosen
function EVENTS:Connect(BindableEvent: RBXScriptSignal, Callback: () -> any, Mode: string, EventGroup: string)
local Event: RBXScriptConnection
if Mode == "Default" then
Event = BindableEvent:Connect(Callback)
elseif Mode == "Once" then
Event = BindableEvent:Once(Callback)
elseif Mode == "Paralell" then
Event = BindableEvent:ConnectParallel(Callback) --# script that executes must be parented to an actor!
else
assert(Mode, "Can't connect event with mode that doesn't exist!")
end
if EventGroup and EventGroups[EventGroup] then
table.insert(EventGroups[EventGroup], Event)
end
return Event
end
function EVENTS:Disconnect(Event, EventGroup: string)
if not EventGroups[EventGroup] then assert(EventGroups[EventGroup], "Can't find EventGroup!") return end
local index = table.find(EventGroups[EventGroup], Event)
EventGroups[EventGroup][index]:Disconnect()
EventGroups[EventGroup][index] = nil
end
function EVENTS:CreateEventGroup(Name: string)
if not EventGroups[Name] then
EventGroups[Name] = {}
else
warn("EventGroup already exists!")
end
end
function EVENTS:DisconnectEventGroup(Group: string)
if EventGroups[Group] then
for _, Event in EventGroups[Group] do
Event:Disconnect()
table.remove(EventGroups[Group], _)
end
end
table.clear(EventGroups[Group])
EventGroups[Group] = nil
end
function EVENTS:Test()
print(EventGroups)
end
return EVENTS
I looked at luau heap and sometimes values grow