How to check if a group of objects has a certain object value?

So I am trying to make a system where it will check if all of the GUI buttons are green, specificly (0, 85, 0) in RGB and am not sure on how to check if all of the TextButtons in the folder have that background color.

Here is what it looks like in the explorer:
image

I want to check if those TextButtons all have the same RGB background (0, 85, 0) from a local script inside of the GUI.

Thanks for reading!

2 Likes
   for i, v in in ipairs (script.Parent:GetChildren) do
        if not v.Color 3 = Color3.fromRGB(0,85,0) then
        	return
        end
	end
	doSomething()
1 Like

You can use :GetChildren() and then iterate

-- define buttonFolder as a variable
for i, v in ipairs(buttonFolder:GetChildren()) do
    if v:IsA("TextButton") then
        if v.BackgroundColor3 == Color3.fromRGB(0, 85, 0) then
            -- do stuff lol
        end
    end
end
3 Likes

So this would check if all of them were green? I need to to know if every single button is green and not just a singular one. For example, if one was red then the code wouldn’t run, but if it were all green then it would run.

Yes it would since GetChildren means get ALL the children and loop though all of them

1 Like

Then you just define a variable at the start:

local allowed = true

Inside of the for loop where it says -- do stuff lol, something like this would work

allowed = false
break

then after that you can check if allowed == true

1 Like

Okay, I will try this. Thank you for helping.

1 Like

It worked, thank you! I just had to make a variable and add it up to the numbers of buttons and if the number went up to 6 it would fire the event. :smiley: