Whenever I try to add a table of objects or connections to Trove, I get this error
“Failed to get cleanup function for object table: table: 0x5f2f805ed5cd9df5 - Server -”
When I define an empty cleanup function that literally does nothing other than print, it works fine, can I avoid this without the need to make an empty cleanup function or am I missing something?
Example of what errors: (pseudocode)
function obj.new()
local self = setmetatable( {}, obj )
self._trove = Trove.new()
local stuffToCleanup = {}
self._trove:Add(stuffToCleanup) -- This will error
return self
end
Example of what doesn’t error:
function obj.new()
local self = setmetatable( {}, obj )
self._trove = Trove.new()
local stuffToCleanup = {}
function stuffToCleanup:Destroy()
print("Cleaning up!")
end
self._trove:Add(stuffToCleanup) -- This will error
return self
end
Reading through the documentation for :Add, it takes an instance or connection. So it’s probably a type error. So instead of adding a table, just :Add the actual connections. Works similar to janitor connections, where the point is to use :Add to append connections instead of adding them into a table and THEN appending them to trove connection (saves you a step)
Ex:
trove:Add(function()
print("Cleanup!")
end)
or
local part = Instance.new("Part")
trove:Add(part)
or
(your table method)
-- Custom cleanup from table:
local tbl = {}
function tbl:DoSomething()
print("Do something on cleanup")
end
trove:Add(tbl, "DoSomething")
To add onto the other comment I made, if you read how cleanup in trove works, you can very clearly see it’s a type error because you can’t cleanup an empty table.