Repeat until doesn't work?

Nope, It just keeps teleporting the Players and giving them a sword…

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
            InRound[Player.UserId] = true

			Player.Character.Humanoid.Died:Connect(function()
				InRound[Player.UserId] = nil
			end)
		end

    task.spawn(function()
		repeat 
			task.wait(.2)
		until #InRound == 1 or #InRound == 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 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!"
				InRound[Player.UserId] = nil

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

Try this.

Ends the round in a second now.

Here, try this.

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 _, 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, table.find(InRound, Player.UserId))
				-- Use table.find to get the index, table.insert inserts the value you gave it at the next available index 1... 2... 3... etc.
			end)
		end



		repeat 
			task.wait(.2)
		until #InRound <= 1
-- the original #InRound == 1 or 0 statement was "truthy" meaning it was always true, because "or" is a conditional, meaning if #InRound == 0 then "or" is like oh, that's false, here's my other side.
-- which would be "0" which is a truthy type, since 0 doesn't equal false in lua. Meaning the repeat was just breaking after it waited once.

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


		for _, 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, table.find(InRound, Player.UserId))

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

How many people did you test it with?

Hey, fun fact, you can’t just task.spawn his repeat loop, you’re completely ruining the point of it to keep the while task.wait() do loop from restarting the game.

Edit: sorry that came off as really snarky. Just woke up about 30 minutes ago

No problem, it’s always good to learn.
Wouldn’t the repeat until loop cause the .Died event to not emit? Or am I tripping?

No, died will properly Fire when it occurs since it’s an internal event.
Haven’t seen any case where a repeat causes events to misfire, besides maybe custom events/player made bindables.

Alright, thanks for helping out.

1 Like

It worked thanks! Didn’t know the problem was small Thanks!
But could you tell me why that worked? even tho I did 1 or 0?

No problem, Lua is the simplest scripting language (vanilla at least) even more so than Python, but it’s got its weird oversights.

The reason behind it not working is due to the fact you:

  1. Didn’t remove the proper table index because “Player.UserId” wasn’t the proper index for table.remove()
  2. #InRound == 1 or 0 is a truthy statement. If #InRound > 1 then “or” evaluates its right-hand expression, which was 0, which is truthy. 0 == true is “true” in lua.

The or operator is just an evaluator, you need to put conditions on both sides of it because it evaluates them as such. #InRound == 1 or #InRound == 0 would’ve worked, but just #InRound <= 1 is best.

1 Like

Oh, That’s weird I thought or was like normal English “if he has a dog or a cat” will be like “if #InRound == 0 or 1” Because that seems logic I guess not Thanks for the help.

Logical it is but programming needs to be syntactic rather than logistic, and no problem.

1 Like