How to check a folder for blocks with a certain color

I have this code so far for a game where you need to get to the correct color. I am trying to check the folder with all the blocks to see which ones have the correct color and storing that in a table.
How would I do that?

Here is my current code:

local color = game:GetService("ReplicatedStorage").GameData.CurrentColor.Value 
local blocks = game:GetService("Workspace"):WaitForChild("Blocks")

This code I have provided will search through every block in the folder and if one of the blocks color is green it will add it into the greenBlocks table:

local blocks = workspace.Blocks

local greenBlocks = {}

for _, block in pairs(block:GetChildren()) do
    if block.Color == Color3.fromRGB(0, 255, 0) then -- Change the values to whatever color you are detecting
        table.insert(greenBlocks, block)
    end
end
1 Like

How would I make it so instead of green blocks it does it for the current color the value has defined?

1 Like

Try this?:

-- services
local replicatedStorage: ReplicatedStorage = game:GetService("ReplicatedStorage") :: ReplicatedStorage

-- variables
local gameData: any = replicatedStorage:WaitForChild("GameData", 100) :: any
local currentColor: any = replicatedStorage:WaitForChild("CurrentColor", 100) :: any
local colorToSearchFor: Color3 = currentColor.Value :: Color3

local blocks: Folder = workspace:WaitForChild("Blocks", 100) :: Folder
local colorCorrectBlocks: any = {} :: any

-- functions
for index: number, block: BasePart in pairs(blocks:GetChildren() :: any) do
	if (not block:IsA("BasePart")) then
		continue
	end
	
	if (block.Color == currentColor) then
		colorCorrectBlocks[#colorCorrectBlocks + 1] = block
	end
end

print(colorCorrectBlocks)