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

How would I make this script loop/repeat?

Asked by 10 years ago

I looked on the wiki, there was an article on "Loops", but I couldn't get it to work. Anyways, here is the script I tried:

for i = 1, math.huge do
    game.Workspace.Part1.BrickColor = "Bright red"
    wait(1)
    game.Workspace.Part2.BrickColor = "Bright red"
    game.Workspace.Part1.BrickColor = "Black"
    wait(1)
    game.Workspace.Part3.BrickColor = "Bright red"
    game.Workspace.Part2.BrickColor = "Black"
    wait()
    break
end

3 answers

Log in to vote
2
Answered by 10 years ago

the for loop is for repeating a set number of times

ie:

for i = 1,10 do
print(i)
wait()
end

would loop 10 times. math.huge is infinity, or as close as infinity as roblox lua allows. so if your trying to make it go on forever, use a while loop.

while true do
wait() -- dont crash
print("hi")
end

you would want to use break when specific standards meet.

while true do
wait()
print("waiting on at least 2 players")
if #game.Players:GetChildren() > 1 then
print("Enough players!")
break
end
end

but in that case, you would want to use something more effective to loop only while true.

while #game.Players < 2 do
wait()
print("waiting on at least 2 players")
end
print("Enough players!")

hope this helped ;)

Ad
Log in to vote
0
Answered by 10 years ago

while true do wait(1) game.Workspace.Part1.BrickColor = "Bright red" wait(1) game.Workspace.Part2.BrickColor = "Bright red" game.Workspace.Part1.BrickColor = "Black" wait(1) game.Workspace.Part3.BrickColor = "Bright red" game.Workspace.Part2.BrickColor = "Black" end

Log in to vote
0
Answered by 10 years ago

Just add while true do and an extra end to your script and you're golden. Example:

while true do
for i = 1, math.huge do
    game.Workspace.Part1.BrickColor = "Bright red"
    wait(1)
    game.Workspace.Part2.BrickColor = "Bright red"
    game.Workspace.Part1.BrickColor = "Black"
    wait(1)
    game.Workspace.Part3.BrickColor = "Bright red"
    game.Workspace.Part2.BrickColor = "Black"
    wait()
    break
end
end

That would loop infinitely.

Answer this question