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

How would I make multiple bricks that change colors randomly?

Asked by 8 years ago
while true do
    game.Workspace.BigFloor.Floor.Light.BrickColor = BrickColor.Random()
    wait(1.0)
end

I'm trying to make a floor that will change colors every second, with the script above. However, this only changes one of the brick's color, even though all of them fall under the directory. I'm a beginning (Maybe beginning beginner? I don't know) scripter, so help is greatly appreciated.

EDIT: Sorry, I caused some confusion, I guess. I meant that one out of many parts was turning colors, and there are multiple parts surrounding the lights.

0
What? What are you trying to do? theCJarmy7 1293 — 8y
0
I'm trying to make a dance floor where the lights change coors awesomersauce 5 — 8y
0
Then my answer should work, just put all the floor parts in a model theCJarmy7 1293 — 8y

2 answers

Log in to vote
-1
Answered by 8 years ago

I recommend you use the GetChildren() function, which gets all of the bricks/other things inside the model. Like this:

while true do
bricks = game.Workspace.BigFloor:GetChildren()
for i = 1, #bricks do
brick =  bricks[i]
brick.Light.BrickColor = BrickColor.Random()
end
end

im a little rusty, but this may work

0
you forgot to wait() so it will freeze your game..... LostPast 253 — 8y
0
You need to properly indent your code. Doing this to larger scripts make it impossible to debug or maintain. AZDev 590 — 8y
Ad
Log in to vote
0
Answered by
theCJarmy7 1293 Moderation Voter
8 years ago

For this, you would loop through all the models children.

There are two ways to do this, both using for loops.

model = game.Workspace.Model

while wait(1) do
    for q=1,#model:GetChildren() do --getChildren() returns a table
        part = model:GetChildren()[q] --get the item in the table
        part.BrickColor = BrickColor.random()
    end
end

That will make the parts flash every second.

model = game.Workspace.Model
--the second way
while wait(1) do
    for i,part in pairs(model:GetChildren()) do -- i and part are both names
-- try printing i with a dictionary and with this
        part.BrickColor = BrickColor.random()
    end
end

For more information on for loops , click on the word for anyway in this answer. Anywhere

0
I would suggest storing the table returned from GetChildren in a variable so you are not calling that function #Children + 1 times. BlackJPI 2658 — 8y
0
I didn't make myself clear last time, sorry. I meant that all of the light's stayed the same, but only one changed. Even saying it now sounds weird. awesomersauce 5 — 8y

Answer this question