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

How could I make this script go through all palette colors efficiently?

Asked by 9 years ago

I need it to check if all sixty-four palette colors have been typed in the TextBox. Thank you in advance for your help!

while wait(1) do
    if script.Parent.Text == "White" then
        pcb = game.Workspace.F1Standard.PrimaryColoredBlocks:GetChildren()
        for _,part in pairs(pcb) do
            if part:IsA("BasePart") then
                part.BrickColor = BrickColor.new("White")
            end
        end
    end
end

1 answer

Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
6 years ago
Edited 6 years ago

You don't need to know a list of all of the palette colors. Notice

script.Parent.Text == "White"

and you write

BrickColor.new("White")

Given the above equality, what's a way to rewrite the second expression so that it doesn't refer to a specific color?

BrickColor.new(script.Parent.Text)

In other words, to handle all colors, you can simply do

while wait(1) do
    local color = BrickColor.new(script.Parent.Text)
    pcb = game.Workspace.F1Standard.PrimaryColoredBlocks:GetChildren()
    for _, part in pairs(pcb) do
        if part:IsA("BasePart") then
            part.BrickColor = color
        end
    end
end

This has a minor problem, which is that it will accept not real color names and default to gray.

You can check that the name of the resulting color matches to prevent this:

while wait(1) do
    local color = BrickColor.new(script.Parent.Text)

    if color.Name == script.Parent.Text then
        pcb = game.Workspace.F1Standard.PrimaryColoredBlocks:GetChildren()
        for _, part in pairs(pcb) do
            if part:IsA("BasePart") then
                part.BrickColor = color
            end
        end
    end
end
0
Umm, this is from 3 years ago. But thanks? SchonATL 15 — 6y
Ad

Answer this question