How to skip lines of code

Hey there!

So i’m not that much of a scripter but iv’e encountered a problem. As you can see from the picture below, i am letting the intermission run down, and check if there are 2 or more ‘ready’ players to play when its done counting down. However, if there is less than 2 players, i want to skip all the way to the end (or back to the beginning) so that the intermission can countdown again and so on. Is there a possible way to do this?

1 Like

I recongize this code, it’s from Alvin_Blox’s tutorial on piggy… keep watching the series to know how to do more stuff with Alvin.

Anyways to the topic of this thread, to reset the Intermission’s timer all over again you can just do this:

if #AvailablePlayers < 2 then
   status.Value = "Two players required (0/2)"
   Round.Intermission(20)
end

Also post the code in the thread next time so we can easily edit it if we want to don’t just post a picture of the code.

1 Like

Since this is in a loop, wouldn’t the function still continue?

If you want it to be a loop then you could just do this:

while #AvailablePlayers < 2 do
   Round.Intermission(20)
end
3 Likes

The whole script is in a while loop

(30 characterss)

My preference is to make an intermission function where the intermission runs, and a starting round function (that chooses the map, etc) that is called when the intermission is finished. Here’s what I mean.

local function StartRound()
    local chosenMap = Round.SelectMap()
    local clonedMap = chosenMap:Clone()
    clonedMap.Name = "Map"
    clonedMap.Parent = workspace
    --Whatever else is here
end

local function StartIntermission()
    while wait() do
        local AvailablePlayers = {}
        Round.Intermission(20)
        for i, v in pairs(game.Players:GetPlayers()) do
            if not v:FindFirstChild("InMenu") then
                table.insert(AvailablePlayers, v)
            end
        end

        if #AvailablePlayers < 2 then
                status.Value= "Two Players Required (0/2)"
                wait(1)
                StartIntermission()
                return
        end
        StartRound()
    end
end

Basically I separated the intermission function and the starting round function. Within the intermission function, I checked to see if there are enough players, and if there aren’t, I used recursion to start the intermission again without proceeding to the rest of the code. If there are enough players the round will start with StartRound()

3 Likes

Thank you, and yes this is from Alvin’s tutorials. I was going to make a piggy based game before he posted his videos, but as hes posted tutorials on how to make the whole game, might as well save weeks of intense thinking and scripting.

Thanks anyway for the help! :+1:

1 Like

I appreciate the time and effort that went into this reply. However, i think ill be using @Nerkonl 's method as it is a much simpler way of doing it. I might change my mind and use your method if i feel uncomfortable.

Thanks for the help! :+1:

2 Likes

How do i call the ‘StartIntermission’ function? If i call it before it wont recognise the function, and if i call it after it just loops.

Any help would be greatly appreciated :+1:

Call it after the function itself.

local function StartRound()
    --BLAH BLAH BLAH
end

local function StartIntermission()
    --BLAH BLAH BLAH
end

StartIntermission()

Iv’e decided to leave the StartRound because there is actually a lot more code under the StartIntermission than what i showed you in the first picture. If i put the StartIntermission outside the function it would just loop. Is there anyway to make it only run once?.

I’m confused, is

local function StartIntermission()

within a loop?

1 Like

Nevermind, i added the while loop in the function and thought that when the StartIntermission() function was called, it actually went back to where the function is instead of performing the function on the line is was called. Hope you understand :joy:

Thanks anyway, i turned out using your method. :+1:

1 Like