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

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

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

✓ Accepted answer

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

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