Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

how to break out of a loop when a condition is met/repeat until a condition is met?

Asked by 5 years ago

Hey!

I'm fairly new to scripting and I'm having trouble how to figure out how to loop some code until a condition is met or repeat some code until a condition is met.

(any help would be greatly appreciated)

Here is my current script:

01local value = game.Workspace.Value
02 
03if value.Value > 20 then
04 
05while true do
06        wait(0.01)
07    script.Parent.Material = Enum.Material.Neon
08wait(0.7)
09    script.Parent.Material = Enum.Material.SmoothPlastic
10wait(0.7)
11 
12end
13if
14value.Value > 20
15then
16    break
17 
18end

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

do repeat

01local value = game.Workspace.Value
02 
03if value.Value > 20 then
04 
05repeat
06        wait(0.01)
07    script.Parent.Material = Enum.Material.Neon
08wait(0.7)
09    script.Parent.Material = Enum.Material.SmoothPlastic
10wait(0.7)
11    value.Value = value.Value + 1
12 
13until value.Value > 30
14end

This repeats it 10 times, cause 20 + 1 + 1 + 1 etc will eventually become 30

Ad

Answer this question