Repeat until doesn't work?

Hi, So I was making a minigame game in 1 hr as a challenge, But I’ve ran into an issue for some reason repeat until isn’t work…

So, basically I’m trying to make it so the Round will end until there are 0 player or 1 (0 Player incase they die in the same time) inside the table.

The Problem I’m having currently is when there are 0 or 1 Player in the table it won’t stop the repeat until (I’ve added prints in the repeat until and I can confirm that it doesn’t stop the repeat until)

Script

		repeat  -- here it repeats
			task.wait(.2)
		until #InRound == 1 or 0 -- until there are 1 or players inside the table

Full Script

while task.wait(2) do


	if #game.Players:GetPlayers() >= 2 then
		local InRound = {}
		for i = 10, 0, -1 do
			ReplicatedStorage.Status.Value = "Intermission: " .. i
			task.wait(1)
		end

		local ChoosenMapClone = MapsFolder["Volcano Map"]:Clone()

		ChoosenMapClone.Parent = game.Workspace
		ReplicatedStorage.Status.Value = "Choosen Map was " .. ChoosenMapClone.Name

		task.wait(2)


		for i,Player in pairs(game.Players:GetPlayers()) do
			Player.Character.HumanoidRootPart.CFrame = ChoosenMapClone.Spawn.CFrame

			local Sword = game.ReplicatedStorage.Items.ClassicSword:Clone()
			Sword.Parent = Player.Backpack
			table.insert(InRound, Player.UserId)

			Player.Character.Humanoid.Died:Connect(function()

				table.remove(InRound, Player.UserId)
			end)
		end



		repeat 
			task.wait(.2)
		until #InRound == 1 or 0

		if #InRound == 0 then
			ReplicatedStorage.Status.Value = "Tied, No one has won the Game!"
		end


		for i,Player in pairs(game.Players:GetPlayers()) do
			if table.find(InRound, Player.UserId) then
				local PlayerSword = Player.Character:FindFirstChild("ClassicSword") or Player.Backpack:FindFirstChild("ClassicSword")
				Player.Character.HumanoidRootPart.CFrame = game.Workspace.SpawnLocation.CFrame
				Player:FindFirstChild("leaderstats").Wins.Value += 1
				ReplicatedStorage.Status.Value = Player.DisplayName .. " Has won the Game!"
				table.remove(InRound, Player.UserId)

				if PlayerSword then
					PlayerSword:Destroy()
				end
			end
		end
	end
end

#InRound will never be equal to 1 because the repeat until loop just has a wait in it.
The simplest way in your current code would be to include the code above the loop inside the repeat loop so it’s actually checking the player count:

repeat
     local InRound = {}
    for i,Player in pairs(game.Players:GetPlayers()) do
	       Player.Character.HumanoidRootPart.CFrame = ChoosenMapClone.Spawn.CFrame

		local Sword = game.ReplicatedStorage.Items.ClassicSword:Clone()
		Sword.Parent = Player.Backpack
		table.insert(InRound, Player.UserId)

		Player.Character.Humanoid.Died:Connect(function()

		table.remove(InRound, Player.UserId)
		end)
	end
    task.wait(.2)
until #InRound == 1 or 0

But won’t that just keep adding the Player that dies to the table?

Ah yeah, I actually just noticed the Died event inside the loop. Give me a second to actually read all the code…

for i,Player in pairs(game.Players:GetPlayers()) do

Try using ipairs here instead.

Sadly, didn’t work.

What’s the point of that?

However inserting break command?

1 Like

This is not how it works.
Do this instead:

until #InRound == 1 or #InRound == 0 
2 Likes

Try this:

repeat
    local InRound = {}
    for i,Player in pairs(game.Players:GetPlayers()) do
        if Player:FindFirstChild("Dead") then
            continue
        end
	       Player.Character.HumanoidRootPart.CFrame = ChoosenMapClone.Spawn.CFrame

		local Sword = game.ReplicatedStorage.Items.ClassicSword:Clone()
		Sword.Parent = Player.Backpack
		table.insert(InRound, Player.UserId)

		Player.Character.Humanoid.Died:Connect(function()
            local BoolValue = Instance.new("BoolValue")
            BoolValue.Parent = Player
            BoolValue.Name = "Dead"
		    table.remove(InRound, Player.UserId)
		end)
	end
    task.wait(.2)
until #InRound == 1 or #InRound == 0

Then remove all bool values after round ends.

Actually I think this is your problem. You need to use table.find to find the player Id and then remove the correct index.

That’s wrong, we insert them into the table first.

I’ll try that thanks for replying.

1 Like

Shouldn’t it be

table.insert(InRound, Player.UserId , Player.UserId)

if you are inserting them into the UserId index though?

table.insert(InRound, Player.UserId) - Outputs [1] = 1502810110
table.insert(InRound, Player.UserId , Player.UserId) - Outputs [1502810110] = 1502810110

Sorry… What no tables only hold 2?

1 Like

no in this case, the first Player.UserId will be the index, and the second will be the value.

1 Like

It just keeps teleporting the Player and giving them a sword…

Could someone help, Nothing is working…

1 Like

When you use table.insert you aren’t giving it a value so it’s taking the userid as the value and inserting it in the next available index.

Did it work?