How to calculate percentage of blocks according to color?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to be able to change the color of the big blocks into the same color as the small blocks depending on how many of the small blocks are colored. For example,

If all of the small blocks are brown, then all of thee big blocks would also be brown. But,

If only 2 of the small blocks were brown, then only half of the big blocks would be brown and the other half would be remaining un-colored. However,

I would like to be able to do this with multiple colors at once no matter what size of each small or big.

  1. What is the issue? Include screenshots / videos if possible!
    I have no idea how to go about this and I need a little bit of guidance to get me started on this. I am trying to create an equal amount of color between the two without disrupting the other colors if I don’t have too
local bigBlocks = game.Workspace.BigBlocks
local smallBlocks = game.Workspace.SmallBlock
  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried asking around, looking through the dev forum, etc but I was not able to get an exact solution to what I am trying to do.

Can somebody help me get started with this?

First of all, how do your bricks become colored?

Are the blocks changed by a script or by the player?

Get the amount of parts by colors

example;

local amountBlue = 5
local AmountRed = 5
local AmountBrown = 5
local Total = amountBlue + AmountRed  + AmountBrown 
local OurNumber = AmountRed 
print("Our percentage =",(Total/OurNumber ) * 10)

The small brick colors will be changed by script. When that happens, I am hoping to calculate the amount of big blocks that need to be colored corresponding to the small blocks.

You can utilize loops in order to go through all the blocks and determine their color.
Additionally you can ultilize part:GetPropertyChangedSignal to determine when a color changes. (If that’s what you are looking for)

part:GetPropertyChangedSignal("BrickColor"):Connect(onBrickColorChanged)

How regarding how to change a percentage of blocks we can utilize an array to store the colors found and replicate that over on the larger blocks

local colors = {} -- this is our array
for _,part in ipairs(Workspace.SmallBlock) do
   if colors[part.BrickColor] then
       colors[part.BrickColor] += 1 -- adding one 
   else
       colors[part.BrickColor] = 1 -- creating a new color value in the table
   end
end

If you don’t know what this array will do, lets say for example we have 4 blocks with the color: 1 Red, 2 Yellow, 1 Green
Our array would be filled like this after the loop goes through

colors = {"Red" = 1, "Yellow" = 2, "Green" = 1}

We can use that now in order to determine the percentage of colored blocks by division.
(amount / total amount)

for colorName, numberOfSmallBlocks in pairs(colors) do
   local percentage = numberOfSmallBlocks / #Workspace.SmallBlock:GetChildren()
   -- Workspace.SmallBlock:GetChildren will return a table, put a # in front to get the total amount of instances.
   print(colorName .. " is ".. percentage )
end

Finally we can use that percentage to color the larger blocks :stuck_out_tongue:

local blocksColored = 1 -- This variable will keep track of our big blocks
for colorName, numberOfSmallBlocks in pairs(colors) do
   local percentage = numberOfSmallBlocks / #Workspace.SmallBlock:GetChildren()
   for i = blocksColored, math.floor(#Workspace.BigBlocks:GetChildren() * percentage) + blocksColored do
   -- This seems very complicated, but if you think about it, all we are doing here
   -- is starting at the first not colored block and using the percentage to determine
   -- how many more blocks we should color
      #Workspace.BigBlocks:GetChildren()[i].BrickColor = colorName
      blocksColored += 1
   end
end

Anyways, these are just things to consider and ways to apply various scripting techniques to try and solve your problem. Feel free to ask questions about any of this.