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

How to mass change decal color?

Asked by 3 years ago

I've recently been experimenting with realistic-looking hair in Roblox studio and came across a grass plugin that would add grass (Landscape Brush tool). This plugin adds a custom mesh along with a decal into the workspace. The plugin worked very well; The hair was SUPER realistic. No, my problem was that I couldn't change the colour of the grass all at once. I've tried making a script(As shown below), but it doesn't seem to work. I could go in and manually change each piece, but that would be a huge waste of time, especially since there are at least a hundred.

local this = script.Parent
local grass = this:GetChildren("Grass")
local grassDecal = grass:GetChildren("Decal")

function Color()
    grassDecal.Color3(170,0,0)
end

This is placed inside the model that contains both the part that needed hair along with the grass. (How do you add pictures in the forum?)

2 answers

Log in to vote
1
Answered by
Elyzzia 1294 Moderation Voter
3 years ago

GetChildren doesn't take any arguments, it just gives you every single child

also, you can't change the properties of multiple children at once with a single assignment; you have to iterate over every single one with a for loop

local this = script.Parent -- no idea why you do this but let's just go with it

local function Color()
    for _, child in pairs(this:GetChildren()) do
        if child.Name == "Grass" then
            child.Color = Color3.fromRGB(170, 0, 0) -- Color3.new is from a 0-1 scale, you need to use Color3.fromRGB for 0-255
            for _, decal in pairs(child:GetChildren()) do
                if decal:IsA("Decal") then -- if the decals are the only children of each blade of grass, then you can remove this part
                    decal.Color3 = Color3.fromRGB(170, 0, 0)
                end
            end
        end
    end
end
0
Thanks! Boomboyag 14 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

I guess this isn't an entire answer, but I found that I can duplicate the grass part, change the color, and then make it into a custom brush, therefore nullifying the problem.

Answer this question