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

Is it possible to use a for loop to change brick colors?

To be more specific, I mean for example this:

for i =1,10 do
brick.BrickColor = BrickColor.new("Really red")
wait(0.5)
brick.BrickColor = BrickColor.new("White")


I know it's jumbled and doesn't make sense. But I'm just trying to give a vague idea of what I mean. Basically, what I want to do, is make the brick flash from red to white in a certain point in the script and then stop. Any ideas? All help is great!

1 comment

0

You'd probably want to put another wait(.5) after changing the color to white. Otherwise, it'd just instantly switch back to red.

3 answers

✓ Accepted answer

You could do this

x = 0
while x < 10 do
brick.BrickColor = BrickColor.new("Really red")
wait(.5)
brick.BrickColor = BrickColor.new("White")
x = x + 1
end

The brick will change to red and back to white 10 times.

3 comments

1

not only is this impractical, It's not what he wants!

0

What does he want? I can't quite figure it out.

2

If you want to do something a certain number of times, use a for loop.

Hey, I have fixed up your script a bit, and added some information to it, via comments. Here ya go!

for i =0,10,1 do --if you noticed, i changed the "for i=1,10" because if it was 1,10 it would only be 9 times!
	brick.BrickColor = BrickColor.new("Really red")
	wait(0.5)
	brick.BrickColor = BrickColor.new("White")
	wait(0.5)
end

--[[
	basically, the for loop will add 1 to the variable i until it reaches 10, thus making it loop 10 times.
	If you have any further questions, just reply! Have a great day!
--]]

2 comments

0

"for i = 1,10 do" loops 10 times. This would go 11 times.

The Answer from csmz v

for i =0,10,1 do --if you noticed, i changed the "for i=1,10" because if it was 1,10 it would only be 9 times!
    brick.BrickColor = BrickColor.new("Really red")
    wait(0.5)
    brick.BrickColor = BrickColor.new("White")
    wait(0.5)
end
--[[
    basically, the for loop will add 1 to the variable i until it reaches 10, thus making it loop 10 times.
    If you have any further questions, just reply! Have a great day!
--]]

This would work but there's a quicker way to do it as well.

for i = 0, 10 do
	-- This portion was fine but your code on top was missing an end, not sure if you just forgot it.
	brick.BrickColor = BrickColor.new("Really red")
	wait(0.5)
	brick.BrickColor = BrickColor.new("White")
end

Now if you notice, it's almost identical to the one you had. All I did was changed the i = 1,10 to i = 0, 10 so we run the loop 10 Times (assuming you want 10) and added an end. Obviously you'd still have to set the value of "brick" to the part, but I assume you know that.

1 comment

0

Runs 11 times and you made his code even worst.

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