Hello, I’m wanting to make it so if all the frames background colours are green then it deletes the GUI, but if they don’t have all have their background colours green then it does something else.
My main issue is detecting if all frames background colours are green or not.
Here is my current code:
for _, selectedBoxes in pairs(script.Parent.SelectedBoxes:GetChildren()) do
if selectedBoxes.BackgroundColor3 == Color3.fromRGB(0, 85, 0) then
-- if they are all green?
else
-- if they are not all green??
end
end
When I select all of the correct ones (that should be green) it prints that it is correct and also that it isn’t correct even though it is, and the same if I do it incorrectly, it says it’s correct and wrong when it’s wrong.
Make sure to verify that what you are selecting is the correct item: Are they all frames? When you look in properties is the BackgroundColor3 actually 0,85,0? If you have any invisible frames and you didn’t set the color you will run into this problem.
if selectedBoxes:IsA("Frame") then
if selectedBoxes.BackgroundColor3 == Color3.fromRGB(0, 85, 0) then
print("green")
else
print("not green")
end
end
it looks like it goes through each box in a loop and prints “overall correct/incorrect” rather than just exiting the loop whenever it finds one that is incorrect. Can’t really do much without the code for the part that says “overall correct”
for _, selectedBoxes in pairs(script.Parent.SelectedBoxes:GetChildren()) do
if selectedBoxes:IsA('Frame') then
if selectedBoxes.BackgroundColor3 == Color3.fromRGB(0, 85, 0) then
print("all green")
else
print("all / some not green")
end
end
end
Here’s the code after there has been 6 boxes selected.
elseif numberOfBoxesSelected == 6 then
for _, remainingBoxes in pairs(script.Parent.Frame:GetChildren()) do
remainingBoxes.Visible = false
remainingBoxes.LocalScript.Disabled = true
end
for _, remainingFrames in pairs(script.Parent.CopyFrames:GetChildren()) do
remainingFrames.Visible = true
end
for _, selectedBoxes in pairs(script.Parent.SelectedBoxes:GetChildren()) do
if selectedBoxes:IsA('Frame') then
if selectedBoxes.BackgroundColor3 == Color3.fromRGB(0, 85, 0) then
print("all green")
else
print("all / some not green")
end
end
end
else
Oh, I think I see what you’re doing. Something like this is what you might be looking for? You will have to find the results in the loop, but printing them during the loop will execute the print code whenever it finds something that matches your requirements
local allGreen= true
local greenCount = 0
for _, selectedBoxes in pairs(script.Parent.SelectedBoxes:GetChildren()) do
if selectedBoxes:IsA('Frame') then
if selectedBoxes.BackgroundColor3 ~= Color3.fromRGB(0, 85, 0) then
allGreen = false
else
greenCount += 1
end
end
end
print("All green: " .. allGreen, "Number correct: " .. greenCount)