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

How do i use for loops for changing brick color?

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

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!

7 comments

0

Yes!! thank you. I lost my practice because i stopped scripting for 6 months so now im new again :D

0

@MTamidex Glad I could help! Be sure to accept my answer!

0

Need to click in the little star?

0

i think i dont have the reputation needed

0

no - click on the tick button that says Accept Answer below the answer

0

no tick for me

0

You sure? Everyone is allowed to accept an answer, if it's their question

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