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
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
You can count how many children an instance has by using the GetChildren() function and the # operator.
#instance.Parent:GetChildren() > 1
Check if the Instance’s parent has more than 1 children.
So i can do ?
if #instance.Parent:GetChildren() > 1 then
print(Instance has sibilings)
end
This returns a boolean so yes.
if x then
accepts anything and will run as long it’s not false
or nil
.
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.