Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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

1 comment

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

This discussion is preserved as it was. New answers, comments, and votes are closed.