Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How would I make multiple bricks that change colors randomly?

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.

3 comments

0

What? What are you trying to do?

0

I'm trying to make a dance floor where the lights change coors

0

Then my answer should work, just put all the floor parts in a model

2 answers

✓ Accepted answer

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

2 comments

0

you forgot to wait() so it will freeze your game.....

0

You need to properly indent your code. Doing this to larger scripts make it impossible to debug or maintain.

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

2 comments

0

I would suggest storing the table returned from GetChildren in a variable so you are not calling that function #Children + 1 times.

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.