Help detecting whether a defined instance is an ancestor of another instance

Hello!

I have a script using the Part:GetTouchingParts() method to get the parts that my model is touching. I then have another section of the script that iterates through each part of the returned table. This is supposed to check if the part in the table is a descendant of the model or if the model is an ancestor of the part (It could work both ways) and then remove it from the table if it is.

The problem is that there is no operator or method to do something like IsAncestorOf() or IsDescendantOf().

Here is what I have so far:

local Touching = Model:GetTouchingParts()
	
for i, Part: BasePart in pairs(Touching) do
	-- Check for the ancestor or descendant... (Need help here)
		table.remove(Touching, i)
	end
end

Any help would be greatly appreciated! Thank you for your time!

2 Likes

Could you just call FindFirstAncestor and FindFirstDescendant on the model?

1 Like

I could but I can only provide a string into the method, not an instance. I need a way to check the relationship between two instances that are already defined.

Hmmm uhh you could use game:FindFirstChild(instance, true) and return the instance.

1 Like

Wait. I’m stupid. There is a :IsDescendantOf() method…

Sorry for wasting your time and thank you for attempting to help.

No it’s no worries! I’m on the freeway right now so thats why my responses took a while to send.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.