function Maid.DoCleaning(Y)local b=Y._tasks for Y,e in pairs(b)do if typeof(e)=="\082\066\088\083\099\114\105\112\116\067\111\110\110\101\099\116\105\111\110"then b[Y]=nil e:Disconnect()end end local e,s=next(b)while s~=nil do b[e]=nil if type(s)=="\102\117\110\099\116\105\111\110"then s()elseif typeof(s)=="\082\066\088\083\099\114\105\112\116\067\111\110\110\101\099\116\105\111\110"then s:Disconnect()elseif s.Destroy then s:Destroy()elseif Promise.Is(s)then s:Cancel()end e,s=next(b)end end

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

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

	-- Clear out tasks table completely, even if clean up tasks add more tasks to the maid
	local index, task = next(tasks)
	while (task ~= nil) do
		tasks[index] = nil
		if (type(task) == "function") then
			task()
		elseif (typeof(task) == "RBXScriptConnection") then
			task:Disconnect()
		elseif (task.Destroy) then
			task:Destroy()
		elseif (Promise.Is(task)) then
			task:Cancel()
		end
		index, task = next(tasks)
	end
end

