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

Am I using the while CONDITION do function correctly?

It has been a while since I have scripted and decided to refresh myself. What I am trying to do is create a brick and allow it to change colors until a certain color (green in this case).

a = Instance.new("Part", workspace)

while BrickColor.Green() do
	wait(0.1)
	a.BrickColor = BrickColor.Random()
	wait(0.1)
end

2 answers

A simple way to do this is with a repeat function.

Simple as this;

--I really don't know how to tab repeat functions, lol.
local p=Instance.new("Part",workspace)
repeat 
	p.BrickColor=BrickColor.Random() --Keep changing the Brick's color
	wait() 
until --until
	p.BrickColor==BrickColor.Green() --the brick's color equals green.

1 comment

0

I want to do this with the while condition do function though.

I have both the answer, and a recommendation: Answer

a = Instance.new("Part", workspace)

while a.BrickColor ~= BrickColor.Green() do -- You need to define the brick that you are checking the brickcolor of. How else would ROBLOX know what brick you want to change the brickColor of? Also using the ~= (not equal) statement to repeat the loop until the brickcolor is green. 
    a.BrickColor = BrickColor.random() 
    wait(0.2) -- Two waits are not neccessary in while loops
end

Recommendation Go to the View tab, and on the 5th column, press the Output button. This output will show what your scripts print, error, and warn you about.

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