Roblox Studio Command Bar Command Help

Hello,

I’m trying to look for code that could help me with changing the colour of a couple parts in some models.

By command Bar I mean this:

I have a folder in workspace called Trees and then a couple models in the folder called “Tree”
image

I’m just trying to make it so when I run a command in the command bar it changes the “Part”'s Colour to whatever colour I enter in the script at the time.

I’ve tried looking for simullar scripts but haven’t found anything. Can anyone help?

game.Workspace.Trees.Tree.Part.Color = Color3.fromRGB(0, 255, 0)

–between () add the color you want.

Would this do it for all models and parts? As theres multiple models and parts.

Hold on, I think I have it.

local treesFolder = game.Workspace.Trees
local desiredColor = Color3.fromRGB(255, 0, 0) 

for _, treeModel in pairs(treesFolder:GetChildren()) do
    if treeModel:IsA("Model") then
        for _, part in pairs(treeModel:GetDescendants()) do
            if part:IsA("Part") and part.Name == "Part" then
                part.BrickColor = BrickColor.new(desiredColor)
            end
        end
    end
end

I’ve tested it and it works, just gonna look around my map to see if its done it all.

You can select all the models and then use the Selection to get them in an array. Then, iterate over them.

for i, v in ipairs(game:GetService("Selection"):Get()) do
    for _, c in ipairs(v:GetDescendants()) do
        c.Color = Color3.fromRGB(255, 255, 0)
    end
end
1 Like
local folder = -- put ur folder here 

local function changeColor(part)
    if part:IsA("Part") then
        part.BrickColor = BrickColor.new(Color3.fromRGB(255, 0, 0)) 

    end
end

for _, model in ipairs(folder:GetChildren()) do
    if model:IsA("Model") then
        for _, part in ipairs(model:GetDescendants()) do
            changeColor(part)
        end
    end
end

Something a tiny bit similar but different from using the “Selection”

local treesFolder = game.Workspace.Trees
local desiredColor = Color3.fromRGB(255, 0, 0) 

for _, treeModel in pairs(treesFolder:GetChildren()) do
    if treeModel:IsA("Model") then
        for _, part in pairs(treeModel:GetDescendants()) do
            if part:IsA("Part") and part.Name == "Part" then
                part.BrickColor = BrickColor.new(desiredColor)
            end
        end
    end
end

Pretty sure it’s doing the same thing though.

then u can mark yours as solved

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.