How to detect if Instance has sibiling?

Lets say I have a instance inside a model, how can I use a script to see if the Instance’s parent (model) has another instance at all?

Model == true
|
|_ Instance1
|
|_ Instance2

Model == false
|
|_ Instance1
2 Likes

You can count how many children an instance has by using the GetChildren() function and the # operator.

1 Like
#instance.Parent:GetChildren() > 1

Check if the Instance’s parent has more than 1 children.

2 Likes

So i can do ?

if #instance.Parent:GetChildren() > 1 then
   print(Instance has sibilings)
end
1 Like

This returns a boolean so yes.
if x then accepts anything and will run as long it’s not false or nil.

1 Like

Not to bother you again, but is # operator same as tonumber()?

It’s the length operator, it gets the length of the table, a string (or returns the value and run the __len metamethod), in this case, :GetChildren() returns a table so #instance.Parent:GetChildren() gets the length of the children.

2 Likes