Updated Code:
local Thing = {}
Thing.__index = Thing
local allThings = {}
local listeners = {}
local function UpdateAll()
for _, callback in listeners do
callback()
end
end
function Thing.New()
local self = setmetatable({}, Thing)
table.insert(allThings, self)
UpdateAll()
return self
end
function Thing:Destroy()
for i, v in ipairs(allThings) do
if v == self then
table.remove(allThings, i)
break
end
end
UpdateAll()
end
function Thing.Changed(callback)
table.insert(listeners, callback)
end
function Thing.All()
return allThings
end
return Thing
Example Usage:
local Thing = require(game.ServerScriptService.Rojo.libs.firerecieve)
local all = Thing.All()
Thing.Changed(function()
all = Thing.All()
end)
print(all)
local thing = Thing.New()
print(all)
thing:Destroy()
print(all)
What do you think of this @sudden schooner