function Janitor.__index.LinkToInstance(U,L,c)local M local r=c and newproxy(false)or LinkToInstanceIndex local W=L.Parent==nil local A=setmetatable({},Disconnect)local function q(L,c)if A.Connected then L=nil W=c==nil if W then task.defer(function()if not A.Connected then return elseif not M.Connected then U:Cleanup()else while W and(M.Connected and A.Connected)do task.wait()end if A.Connected and W then U:Cleanup()end end end)end end end M=L.AncestryChanged:Connect(q)A.Connection=M if W then q(nil,L.Parent)end L=nil return U:Add(A,"\068\105\115\099\111\110\110\101\099\116",r)end

function Janitor.__index:LinkToInstance(Object, AllowMultiple)
	local Connection
	local IndexToUse = AllowMultiple and newproxy(false) or LinkToInstanceIndex
	local IsNilParented = Object.Parent == nil
	local ManualDisconnect = setmetatable({}, Disconnect)

	local function ChangedFunction(_DoNotUse, NewParent)
		if ManualDisconnect.Connected then
			_DoNotUse = nil
			IsNilParented = NewParent == nil

			if IsNilParented then
				task.defer(function()
					if not ManualDisconnect.Connected then
						return
					elseif not Connection.Connected then
						self:Cleanup()
					else
						while IsNilParented and Connection.Connected and ManualDisconnect.Connected do
							task.wait()
						end

						if ManualDisconnect.Connected and IsNilParented then
							self:Cleanup()
						end
					end
				end)
			end
		end
	end

	Connection = Object.AncestryChanged:Connect(ChangedFunction)
	ManualDisconnect.Connection = Connection

	if IsNilParented then
		ChangedFunction(nil, Object.Parent)
	end

	Object = nil
	return self:Add(ManualDisconnect, "Disconnect", IndexToUse)
end
