function Janitor.__index.LinkToInstance(i,L,m)local M local N=m and newproxy(false)or LinkToInstanceIndex local T=L.Parent==nil local x=setmetatable({},Disconnect)local function f(L,m)if x.Connected then L=nil T=m==nil if T then(coroutine.wrap(function()Heartbeat:Wait()if not x.Connected then return elseif not M.Connected then i:Cleanup()else while T and(M.Connected and x.Connected)do Heartbeat:Wait()end if x.Connected and T then i:Cleanup()end end end))()end end end M=L.AncestryChanged:Connect(f)x.Connection=M if T then f(nil,L.Parent)end L=nil return i:Add(x,"\068\105\115\099\111\110\110\101\099\116",N)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
				coroutine.wrap(function()
					Heartbeat:Wait()
					if not ManualDisconnect.Connected then
						return
					elseif not Connection.Connected then
						self:Cleanup()
					else
						while IsNilParented and Connection.Connected and ManualDisconnect.Connected do
							Heartbeat: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
