Instance:IsChildOf(Instance)

I can just use InstanceA.Parent == InstanceB

The Problem

Currently, it is inconvenient to check if an instance is a child of another instance. The way I would go about checking if InstanceA is a child of InstanceB would be similar to this:

local InstanceA
local InstanceB

local IsChild = false
for i, child in pairs(InstanceB:GetChildren()) do
	if child == InstanceA then
		IsChild = true
		break
	end
end

However, if i wanted to check if InstanceA is a descendant of InstanceB, all I have to do is the following:

local InstanceA
local InstanceB

local IsDescendant = InstanceA:IsDescendantOf(InstanceB)

This is far more convenient than the for loop above, which is why I am suggesting the following:

Instance:IsChildOf(Instance)

Use Case / Benefits

  • Used for checking if something is parented by something, regardless of the child’s name.
  • This would replace the bulky for loop remedy

If I somehow overlooked an easier way to currently do this, please let me know!

4 Likes

This topic was automatically closed after 1 minute. New replies are no longer allowed.