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

This part of my duels game isn't working correctly?

Asked by 6 years ago

This is a part of my Duels Game script and the problem is whenever the timer reaches 0 or a player wins, I'm trying to respawn the player. The problem is, it's infinity respawning the player instead of breaking out the loop. If anyone knows the problem, that would be awesome.

for  gametimer = 60, 0, -1 do
    if gametimer == 0 then
        status.Value = "Time up!"
        for _, v in pairs(_G.duelers) do
            if v then
                v:LoadCharacter()
            end
        end
        break
    end

    if #_G.duelers == 1 then
        for _, v in pairs(_G.duelers) do
            if v then
                status.Value = v .. " is the winner!"
                game.Players[v].leaderstats.Cash.Value = game.Players[v].leaderstats.Cash.Value + 50
                v:LoadCharacter()
                break
            end
        end
    elseif #_G.duelers == 0 then
        status.Value = "There was a tie!"
        break
    else
        status.Value = gametimer .. " seconds until the round is over!"
    end

    wait(1)
end

1 answer

Log in to vote
0
Answered by 6 years ago

Scripts run top till down You might be confused when coming to for loops but it does the same thing It runs the same thing for, for loops then

for  gametimer = 60, 0, -1 do
          -- Do things here
    end
     status.Value = "Time up!"
        for _, v in pairs(_G.duelers) do
            if v then
                v:LoadCharacter()
            end
        end

    if #_G.duelers == 1 then
        for _, v in pairs(_G.duelers) do
            if v then
                status.Value = v .. " is the winner!"
                game.Players[v].leaderstats.Cash.Value = game.Players[v].leaderstats.Cash.Value + 50
                v:LoadCharacter()
                break
            end
        end
    elseif #_G.duelers == 0 then
        status.Value = "There was a tie!"
        break
    else
        status.Value = gametimer .. " seconds until the round is over!"
    end

    wait(1)
end

If you have other things to fix then fix it If this worked then please submit it

0
He used the 'break' in order to get out of the for loop..Also he should be checking for the winners within the loop in case they finish on time iamnoamesa 674 — 6y
Ad

Answer this question