A Maid is provided tasks which it will handle when it is told to cleanup.
A task may be a function, connection, Roblox Instance, or table with a
Connections are always disconnected before other tasks.
This Maid implementation is based on the Maid from Nevermore Engine by Quenty.
local maid = Maid.new() -- Something you might need to clean up: local part = workspace.SomePart -- Add tasks to the maid. A task can be... maid:addTask(part) -- a Roblox instance maid:addTask(part.Touched:Connect(...)) -- a connection maid:addTask(function() ... end) -- a function maid:addTask(Event.new()) -- something with a cleanup function -- You can add tasks by id: maid["somePart"] = Instance.new("Part") -- "somePart" is a task id maid["somePart"] = Instance.new("Part") -- the first part gets cleaned up -- because "somePart" got overwritten! -- Instruct the maid to perform all tasks: maid:cleanup()
Constructs a new Maid.
Stores this maid's tasks
Executes the given task
Give this maid a task, and returns its id.
Cause the maid to do all of its tasks then forget about them