function Maid.DoCleaning(m)local C=m._tasks for m,W in pairs(C)do if typeof(W)=="\082\066\088\083\099\114\105\112\116\067\111\110\110\101\099\116\105\111\110"then C[m]=nil W:Disconnect()end end local W,e=next(C)while e~=nil do C[W]=nil if type(e)=="\102\117\110\099\116\105\111\110"then e()elseif type(e)=="\116\104\114\101\097\100"then local m if coroutine.running()~=e then m=pcall(function()task.cancel(e)end)end if not m then local m=e task.defer(function()task.cancel(m)end)end elseif typeof(e)=="\082\066\088\083\099\114\105\112\116\067\111\110\110\101\099\116\105\111\110"then e:Disconnect()elseif e.Destroy then e:Destroy()end W,e=next(C)end end

function Maid:DoCleaning()
	local tasks = self._tasks

	-- Disconnect all events first as we know this is safe
	for index, job in pairs(tasks) do
		if typeof(job) == "RBXScriptConnection" then
			tasks[index] = nil
			job:Disconnect()
		end
	end

	-- Clear out tasks table completely, even if clean up tasks add more tasks to the maid
	local index, job = next(tasks)
	while job ~= nil do
		tasks[index] = nil
		if type(job) == "function" then
			job()
		elseif type(job) == "thread" then
			local cancelled
			if coroutine.running() ~= job then
				cancelled = pcall(function()
					task.cancel(job)
				end)
			end

			if not cancelled then
				local toCancel = job
				task.defer(function()
					task.cancel(toCancel)
				end)
			end
		elseif typeof(job) == "RBXScriptConnection" then
			job:Disconnect()
		elseif job.Destroy then
			job:Destroy()
		end
		index, job = next(tasks)
	end
end
