Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Percentage of an area what colour?

Asked by 6 years ago

Hey,

This may be a strange request but I'm sort of trying to try different things out to learn myself a bit, but I'm just wondering, say I had a map I've built and it's in the map folder in replicated storage, is there any way to find out what percentage of that map is a certain colour.

Example if there 100 blocks on the map, and 25 we're red and 75 were blue how would I get these numbers to work with.

Many thanks benmz41998

1 answer

Log in to vote
0
Answered by
Troidit 253 Moderation Voter
6 years ago
Edited 6 years ago

I'm sure there are multiple ways to figure this problem, but this is how I personally would write it.

R_S=game:GetService("ReplicatedStorage")
Map=R_S.Folder.Map

function FindColors()
    local BlueParts=0 -- The first two variables will be used to count how many blocks of the variable's corresponding color are present.
    local RedParts=0
    for k,block in pairs(Map:GetChildren()) do --For every instance inside of the map
        if block:IsA("BasePart") then --If the instance is a part
            if block.BrickColor.Name=="Really red" then -- If block matches color name
                RedParts=RedParts+1 --Add 1 to the counter
            if block.BrickColor.Name=="Deep blue" then 
                BlueParts=BlueParts+1
            end
        end
    end
    print ("Map: "..Map.Name.." has "..tostring(RedParts).." red parts and "..tostring(BlueParts).." blue parts.")
end

FindColors()

As for the percentage, you can just use the number of parts a certain color has and divide that among the total number of parts.

Ad

Answer this question