function Maid.DoCleaning(N)local K=N._tasks for N,o in pairs(K)do if typeof(o)=="\082\066\088\083\099\114\105\112\116\067\111\110\110\101\099\116\105\111\110"then K[N]=nil o:Disconnect()end end local o,l=next(K)while l~=nil do K[o]=nil if type(l)=="\102\117\110\099\116\105\111\110"then l()elseif typeof(l)=="\082\066\088\083\099\114\105\112\116\067\111\110\110\101\099\116\105\111\110"then l:Disconnect()elseif l.Destroy then l:Destroy()end o,l=next(K)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()
		end
		index, task = next(tasks)
	end
end
