function RxInstanceUtils.observeFirstAncestorBrio(v,S)assert(typeof(v)=="\073\110\115\116\097\110\099\101","\066\097\100 \105\110\115\116\097\110\099\101")assert(type(S)=="\115\116\114\105\110\103","\066\097\100 \099\108\097\115\115\078\097\109\101")return Observable.new(function(f)local H=Maid.new()local u=nil local function q()local q=v:FindFirstAncestorWhichIsA(S)if q then if q~=u then u=q local v=Brio.new(q)H._current=v f:Fire(v)end elseif u then H._current=nil u=nil end end H:GiveTask(v.AncestryChanged:Connect(q))q()return H end)end

function RxInstanceUtils.observeFirstAncestorBrio(instance, className)
	assert(typeof(instance) == "Instance", "Bad instance")
	assert(type(className) == "string", "Bad className")

	return Observable.new(function(sub)
		local maid = Maid.new()

		local lastFound = nil
		local function handleAncestryChanged()
			local found = instance:FindFirstAncestorWhichIsA(className)

			if found then
				if found ~= lastFound then
					lastFound = found
					local brio = Brio.new(found)
					maid._current = brio
					sub:Fire(brio)
				end
			elseif lastFound then
				maid._current = nil
				lastFound = nil
			end
		end

		maid:GiveTask(instance.AncestryChanged:Connect(handleAncestryChanged))
		handleAncestryChanged()

		return maid
	end)
end
