Is there a function similar to COUNT.IF in excel? what I mean is, is there a function (or a way if there isn't) of seeing if all the children complete a certain value
eg: if I run the function with an if statement it will be like if all the children are blue then execute this, I DO NOT MEAN GETCHILDREN OR GETDECENDENTS I want to know if all the parts are blue in a model then execute this.
I'm sorry I'm bad at explaining things
To follow your example let us make a script that checks the color of every part in a model. Here is an example:
local model = script.ExampleModel local listOfItemsThatFitCriterea = {} for i,v in pairs(model:GetChildren()) do -- we are looking through all the children here -- put your if color == blue or whatever then statement in here table.insert(listOfItemsThatFitCriterea, v.Name) -- what this does is it fills the table with the names of the parts that fit our criterea. end end
Hope this helps, if you have any additional questions post them in the comments below. Have a great day scripting!
This function checks all the parts in a model that are blue:
local model = the model you want to check for i,v in pairs(model:GetDecendents()) do if v:IsA("BasePart") and v.BrickColor == "Blue" then -- do stuff end end
You would have to use :GetChildren()
, then as long as you hit the first child that does not evaluate to true in your case, for example the child is green but you are checking if all children are blue, then just return the function.
function () for _, child in pairs(part:GetChildren()) if child ~= blue then return end end -- whatever you want to do if they are all blue here end