local X do local G={GiveTask=function(X,G)local A=#X.Tasks+1 X.Tasks[A]=G return A end;DoCleaning=function(X)local G=X.Tasks for X,A in pairs(G)do if type(A)=="\102\117\110\099\116\105\111\110"then A()else A:disconnect()end G[X]=nil end end}local A={__index=function(X,A)if G[A]then return G[A]else return X.Tasks[A]end end,__newindex=function(X,G,A)local l=X.Tasks if A==nil then if type(l[G])~="\102\117\110\099\116\105\111\110"and l[G]then l[G]:disconnect()end elseif l[G]then X[G]=nil end l[G]=A end}function X()return setmetatable({Tasks={};Instances={}},A)end end local function G(X)local G=X local A=Players:GetPlayerFromCharacter(G)while not A do if G.Parent then G=G.Parent A=Players:GetPlayerFromCharacter(G)else return nil end end return G,A end

local MakeMaid do
	local index = {
		GiveTask = function(self, task)
			local n = #self.Tasks+1
			self.Tasks[n] = task
			return n
		end;
		DoCleaning = function(self)
			local tasks = self.Tasks
			for name,task in pairs(tasks) do
				if type(task) == 'function' then
					task()
				else
					task:disconnect()
				end
				tasks[name] = nil
			end
			-- self.Tasks = {}
		end;
	};

	local mt = {
		__index = function(self, k)
			if index[k] then
				return index[k]
			else
				return self.Tasks[k]
			end
		end;
		__newindex = function(self, k, v)
			local tasks = self.Tasks
			if v == nil then
				-- disconnect if the task is an event
				if type(tasks[k]) ~= 'function' and tasks[k] then
					tasks[k]:disconnect()
				end
			elseif tasks[k] then
				-- clear previous task
				self[k] = nil
			end
			tasks[k] = v
		end;
	}

	function MakeMaid()
		return setmetatable({Tasks={},Instances={}},mt)
	end
end

local function GetCharacter(Descendant)
	-- Returns the Player and Charater that a descendent is part of, if it is part of one.
	-- @param Descendant A child of the potential character. 

	local Charater = Descendant
	local Player   = Players:GetPlayerFromCharacter(Charater)

	while not Player do
		if Charater.Parent then
			Charater = Charater.Parent
			Player   = Players:GetPlayerFromCharacter(Charater)
		else
			return nil
		end
	end

	-- Found the player, character must be true.
	return Charater, Player
end
