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

How would a loop work?

Asked by
blowup999 659 Moderation Voter
9 years ago

What kind of loop would you use if you wanted the loop to keep on going while the rest of the script kept going also because I know some loops you can't do that but I'm not sure which loop can go on while the other parts of the script also go on.

1 answer

Log in to vote
1
Answered by 9 years ago

I will not make a script for you, this seems like a request. But I will help by giving you some loops that I use:

--The "for" loop:
for i = 1, 10 do --Repeats everything before end 10 times
    print(i) --prints how many times it has repeated
end

--The repeat, until loop:

repeat
    if value == true then --To make sure you do not get stuck in a loop
        break --Break the loop if value is true
    end
    wait()
until value == true

--the "function" loop as I call it:

function RepeatMe()
    --code
    RepeatMe() --makes RepeatMe loop
    --If you do not want it to be infinite then add an if statement or something like
    --[[
    if repeat == true then
        RepeatMe()
    end
    ]]--
end

RepeatMe() --Starts the loop

--The while loop:

while true do
    print("OMG HAX")
    wait() --ADD A WAIT! Otherwise the script will overload the game!
end

--or you can do

while value == true do
    print("OMG HAX")
    if value == false then
        break --Break the loop in case it gets stuck
    end
    wait() --ADD A WAIT! Otherwise the script will overload the game!
end

--That's about all I can think of so far...

If you are making a minigame game or something that has rounds then I recommend the function loop.

0
That's not what I meant what I meant is a loop continues and continues and continues while the rest of the script continues doing whatever blowup999 659 — 9y
0
But thanks I got the RepeatMe loop to do that blowup999 659 — 9y
Ad

Answer this question