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