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
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