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

How do i use for loops for changing brick color?

Asked by 9 years ago

I already made a table with the specific colors i want the bricks to change to but i cant quite do the loop.

while wait(120) do part.BrickColor = table[math.random(1,#table)] end -- this is the loop a friend helped me with and then he told me to try with for and pairs.

Thanks in advance.

1 answer

Log in to vote
0
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
9 years ago

If the parameters in the table are BrickColor values, then that script should work fine! Be sure you defined the variable 'table' as well as 'part'! The for loop is used when you want to go through multiple objects/multiple parameters in a table. Say if you wanted a bunch of parts to become that brick color:

table = {"Really red", "Really blue"}

while wait(120) do
    for i,v in pairs(script.Parent:GetChildren()) do
        if v:IsA("Part") then
            v.BrickColor == BrickColor.new(table[math.random(#table)])
        end
    end
end

The above script goes through every child that's a member of the script's parent, checks if it's a part, then changes all of their BrickColors! Your script was a bit confusing, so if you have any questions, be sure to comment!

0
Yes!! thank you. I lost my practice because i stopped scripting for 6 months so now im new again :D MTamidex 0 — 9y
0
@MTamidex Glad I could help! Be sure to accept my answer! Shawnyg 4330 — 9y
0
Need to click in the little star? MTamidex 0 — 9y
0
i think i dont have the reputation needed MTamidex 0 — 9y
View all comments (3 more)
0
no - click on the tick button that says Accept Answer below the answer davness 376 — 9y
0
no tick for me MTamidex 0 — 9y
0
You sure? Everyone is allowed to accept an answer, if it's their question Shawnyg 4330 — 9y
Ad

Answer this question