Hi, I am making a round system for my game, but it doesn’t detect when the player count is 1 or 0. There are no errors. I think the issue is below END OF PLAYER DIED/REMOVED/LEFT comment. Can someone help? Here is my current code:
local RS = game.ReplicatedStorage
local SS = game.ServerStorage
local Maps = SS:WaitForChild("Maps")
local Status = RS:WaitForChild("Status")
local intermissionLength = 15
local Timer = game.ReplicatedStorage.Timer
local data = require(script.Parent["Questions/Answers"])
local highestNumber = 0
local chosen = nil
while true do
Status.Value = "Waiting for enough players! (1/2)"
repeat task.wait() until game.Players.NumPlayers >=2
Status.Value = "Intermission:"
task.wait(3)
Status.Value = "15"
for i=1,intermissionLength do
task.wait(1)
local new = tonumber(Status.Value)-1
Status.Value = tostring(new)
end
--END OF INTERMISSION
local plrs = {}
for i,player in pairs(game.Players:GetPlayers()) do
if player then
table.insert(plrs,player) --add plr
end
end
local padVotes = {
["Construction"] = tonumber(workspace.Lobby.Construction.SurfaceGui.TextLabel.Text),
["Radioactive"] = tonumber(workspace.Lobby.Radioactive.SurfaceGui.TextLabel.Text),
["City"] = tonumber(workspace.Lobby.City.SurfaceGui.TextLabel.Text)
}
for i, v in pairs(padVotes) do
local number = v
if number > highestNumber then
highestNumber = number
chosen = i
end
end
local ChosenMap = tostring(chosen)
task.wait(.3)
if ChosenMap == nil or ChosenMap == "0" or ChosenMap == "nil" then
local AvailableMaps = Maps:GetChildren()
ChosenMap = tostring(AvailableMaps[math.random(1,#AvailableMaps)])
Status.Value = tostring(ChosenMap).. " has been chosen!"
else
Status.Value = tostring(ChosenMap).. " has been chosen!"
end
task.wait(2)
Status.Value = "Game starting!"
task.wait(2)
local ClonedMap = game.ServerStorage.Maps:FindFirstChild(ChosenMap):Clone()
if ClonedMap ~= nil then
if ClonedMap == "Radioactive" then
ClonedMap:PivotTo(CFrame.new(490.263, 79.457, -4.343) * CFrame.Angles(0, 0, math.pi))
elseif ClonedMap == "Construction" then
ClonedMap:PivotTo(CFrame.new(490.263, 35.957, -4.343))
elseif ClonedMap == "City" then
ClonedMap:PivotTo(CFrame.new(490.263, 35.957, -4.343))
end
end
ClonedMap.Parent = workspace
local SpawnPoints = game.ServerStorage.Maps[ChosenMap]:FindFirstChild("SpawnPoints")
if not SpawnPoints then
warn("No spawnpoints found")
end
--END OF CHOOSING MAP
local AvailableSpawns = SpawnPoints:GetChildren()
for i,player in pairs(plrs) do
if player then
local char = player.Character
if char then
char:FindFirstChild("HumanoidRootPart").CFrame = AvailableSpawns[1].CFrame + Vector3.new(0,2,0)
table.remove(AvailableSpawns,1)
local GameTag = Instance.new("BoolValue")
GameTag.Name = "GameTag"
GameTag.Parent = char
else
if not player then
table.remove(plrs,i)
end
end
end
end
--END OF TELEPORTING PLAYERS
Status.Value = "Get ready to play!"
for i,player in pairs(plrs) do
if player then
local character = player.Character
if not character then
print("Player left the game")
table.remove(plrs,i)
elseif character:FindFirstChild("GameTag") then
print(player.Name.. " is still in the game!")
else
table.remove(plrs,i)
end
else table.remove(plrs,i)
print(player.Name.. " has been removed")
end
end
--END OF PLAYER DIED/REMOVED/LEFT
Timer.Value = 15
repeat
if #plrs <= 1 then
break
end
game.ReplicatedStorage.SafeAnswer:FireAllClients()
local questionnum = math.random(#data)
local question = data[questionnum].question
Status.Value = question
Timer.Value = 15
for i=1,15 do
task.wait(1)
local new = Timer.Value-1
Timer.Value = new
end
ClonedMap.Lava.Size += Vector3.new(0,10,0)
if #plrs <= 1 then
break
end
until #plrs <= 1
if #plrs == 1 then
if plrs[1].Character:FindFirstChild("GameTag") then
Status.Value = "The winner is: " ..plrs[1].Name.. "!"
plrs[1].leaderstats.Wins.Value += 1
Timer.Value = 180
end
elseif #plrs == 0 then
Status.Value = "Nobody won!"
Timer.Value = 180
end
Status.Value = "End of game!"
task.wait(2)
for i,player in pairs(game.Players:GetPlayers()) do
local charac = player.Character
if not charac then
print("Player does not have character!")
elseif charac then
if charac:FindFirstChild("GameTag") then
charac.GameTag:Destroy()
player:LoadCharacter()
end
end
end
for i,v in pairs(workspace.StepsFolder:GetChildren()) do
if v.Name == "Step" then
v:Destroy()
end
end
ClonedMap:Destroy()
workspace.Lobby.Construction.SurfaceGui.TextLabel.Text = "0"
workspace.Lobby.Radioactive.SurfaceGui.TextLabel.Text = "0"
workspace.Lobby.City.SurfaceGui.TextLabel.Text = "0"
Timer.Value = 180
task.wait(3)
--END OF GAME ENDING
end