Scripts "for" stopping but not the repeat

Im trying to make a round handler with a sudden death system, but for loop stopping when it hits 0 but the repeat isnt

ive tried printing it and using an intvalue, but it didnt work


	local numb = 0
	local timesudden = 4
	local suddendeath = false
	repeat 
		task.wait(1)
		for none, player in workspace.players.gamers:GetChildren()do
			script.players.Value = none
			if suddendeath == false then
				text.Text = none .. " Players Left" .. " - " .. maplist[mapnumb]
			else 
				text.Text = "SUDDEN DEATH!!!"
			end
			print(none)
			print(timesudden)
			timesudden -= 1
			if timesudden == 0 then
				text.Text = "SUDDEN DEATH!!!"
				suddendeath = true
				game.ReplicatedStorage["the goobler"]:Clone().Parent = workspace
				
			end
			if timesudden <= 0 then
				timesudden = 0
			end
			script.players.Value = none
		end
	until script.players.Value == -1 or script.players.Value == 6
	print("weeeeeeeeeeeeeeeeee")```

Do you mean to use “break” or “continue” in the for loop instead of “repeat until” ?
“break” breaks the for loop and “continue” skips the block of code for this value and continues to the next one.

I’m sorry, I’m pretty new in luau coding but seeing as nobody has replied to you yet I wanted to reply.

If I understood correctly what you’re saying, and the code you provided is the only code modifying the value script.players.Value , then the for loop stops when it stops iterating through the game’s players, just for the repeat to run it again if its until conditions aren’t met.

Now, the repeat breaks until:

your amount of players in the game is either -1 (impossible) or 6, which doesn’t make much sense… if you would like the repeat to stop when there are no more players in the game then compare to 0, not -1 (same logic applies if you would like to stop when there’s only one player left: compare to 1).

wait, so thats what break does? ill try it

im testing the thing, printing the players value to see when its zero, and so it doesnt end when its 1 player

It shouldn’t end, because you’re only ending the repeat until the amount of players is -1 or 6, not 1…

Unless I’m misunderstanding what you’re saying.

im talking about the for loop, not the repeat.

The for loop ends when it ends iterating through all the players in the game and then the repeat runs it again… if you would like the for loop to end early then use break when the player left amount is 1.

That only works for one player, sometimes both players die at the same time, can you help me with zero players too?

If you would like to run some code while there are still 2 or more players in the game, you can use a while loop instead:

while script.players.Value > 1 do
  -- code to run for when there are 2 or more players
end
-- code that runs when there's only one player left, or none.

Sudden death usually triggers a change in rules.. faster damage, insta-kills, or some added hazard. It’s not a separate countdown, it just modifies what happens while time continues.

You’ll have to be very specific about what you want here.
A countdown to 6 or an adjusted time then down to 0.

As is it looks like you’re stopping when there are 6 players left (or -1, which probably never happens). That’s not a countdown at all.. it’s just watching player count.

i did add something, it was a wall that closes in and instakills

Sound like you’re getting the hang of Sudden death. :astonished_face:

ive decided to scrap this, its too complicated for me rn

Ok, we can do whatever you want, stop by anytime.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.