Skip to content

Maid

The Maid class lets you easily watch and clean up objects, events, and other tasks. Written by Quenty, this class has proven itself worthy in some of Roblox's most successful games.


Constructor

Maid.new()

Creates a new Maid instance.

1
local maid = Maid.new()

Methods

GiveTask(task)

Stores a task. The task can be an event connection, an instance or table with a Destroy method, or a function. When the maid's DoCleaning or Destroy method is invoked, these tasks will be cleaned up. Events will be disconnected, instances will be destroyed, and functions will be called.

1
2
3
maid:GiveTask(myModel)
maid:GiveTask(workspace.ChildAdded:Connect(function(obj) end))
maid:GiveTask(function() end)

Returns: number index of the task.


GivePromise(promise)

Stores a promise. If the maid is cleaned up and the promise is not completed, the promise will be cancelled.

1
2
3
4
maid:GivePromise(Promise.Async(function(resolve, reject)
    wait(5)
    resolve()
end))

Returns: Promise


DoCleaning()

Cleans up all the tasks. Event connections will be disconnected, instances will be destroyed, and functions will be called.

1
maid:DoCleaning()

Destroy()

Alias for DoCleaning.

1
maid:Destroy()