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 4 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:

local value = game.Workspace.Value

if value.Value > 20 then

while true do
        wait(0.01)
    script.Parent.Material = Enum.Material.Neon
wait(0.7)
    script.Parent.Material = Enum.Material.SmoothPlastic
wait(0.7)

end
if 
value.Value > 20
then 
    break

end

1 answer

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

do repeat

local value = game.Workspace.Value

if value.Value > 20 then

repeat
        wait(0.01)
    script.Parent.Material = Enum.Material.Neon
wait(0.7)
    script.Parent.Material = Enum.Material.SmoothPlastic
wait(0.7)
    value.Value = value.Value + 1

until value.Value > 30
end

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

Ad

Answer this question