Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Is there a function that uses all the children in a parent?

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

1 comment

0

If I helped you please accept my answer. Otherwise comment to me how I can help you better.

3 answers

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

1 comment

0

Line 3 would error. BrickColor is a BrickColor, a string is a string. Just wrap it in a BrickColor.new"Blue"

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


This discussion is preserved as it was. New answers, comments, and votes are closed.