The title says it all, how do you make something keep going until it reaches to a certain thing, so like if I keep pressing a button and the part keeps changing colors it stops changing colors when it becomes yellow or green idk, I've tried looking at loops and stuff but I don't really know if that option works.
COMMUNITY QUESTION
How to make something keep going until it reaches to a certain thing?
1 answer
Hey man, seems like you talking about loops? For something like your example you would want to do something like:
local button = gui.button
local part = workspace.part
-- Wait for mouse click
button.MouseButton1Click:connect(function()
-- loop the code but break the loop once it has gone red
while part.BrickColor ~= BrickColor.new("Bright red") do
-- if its not red run this code
part.BrickColor = BrickColor.random()
-- in loops always remember to put a wait otherwise the game will freeze
wait(1)
end
-- if the color turns red then the loop will stop yielding and the rest of the code will run
print('The brick is now red')
end)
This was more giving code than an explanation, so for mroe advanced stuff read mroe about loops here: http://wiki.roblox.com/index.php?title=Loops
This discussion is preserved as it was. New answers, comments, and votes are closed.
