function RxInstanceUtils.observeFirstAncestor(b,V)assert(typeof(b)=="\073\110\115\116\097\110\099\101","\066\097\100 \105\110\115\116\097\110\099\101")assert(type(V)=="\115\116\114\105\110\103","\066\097\100 \099\108\097\115\115\078\097\109\101")return Observable.new(function(M)local Q=Maid.new()local h=UNSET_VALUE local function E()local Q=b:FindFirstAncestorWhichIsA(V)if Q~=h then h=Q M:Fire(Q)end end Q:GiveTask(b.AncestryChanged:Connect(E))E()return Q end)end

function RxInstanceUtils.observeFirstAncestor(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 = UNSET_VALUE
		local function handleAncestryChanged()
			local found = instance:FindFirstAncestorWhichIsA(className)
			if found ~= lastFound then
				lastFound = found
				sub:Fire(found)
			end
		end

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

		return maid
	end)
end
