I have this script here that I am using to "end the round." (Checks if the team "Survivors" has zero people) The problem is that it runs, but after that doesn't continuously check if it is true. I tried to add a while loop , but that doesn't seem to work. So how can I make it check until the statement is true?
function waitforwinner()
while wait() do
if #_G.getTeam(game.Teams.Survivors) == 0 then
m = Instance.new("Message",Workspace)
m.Text = "The final survivor was infected. Infected win !Once you respawn the round will begin!"
wait(3)
m:Destroy()
if first_infected.StarterGear.Revolver ~= nil then
first_infected.StarterGear.Revolver:Destroy()
game.Workspace.Field1.Parent = game.Lighting
wait(3)
game.Lighting.Field1.Parent = game.Workspace
_G.blue()--global function makes everyone blue again
if #_G.getTeam(game.Teams.Infected) == 0 then
begin("The round has begun.",3)
GiveGun()
FirstInfected("A player has been randomly infected!",3)
waitforwinner()
end
end
elseif #_G.getTeam(game.Teams.Survivors) >= 1 then-- If time runs out do
wait(400)
m = Instance.new("Message",Workspace)
m.Text = "Time has run out. Survivors win!"
wait(3)
m:Destroy()
end
if first_infected.StarterGear.Revolver ~= nil then
first_infected.StarterGear.Revolver:Destroy()
end
game.Workspace.Field1.Parent = game.Lighting
wait(3)
game.Lighting.Field1.Parent = game.Workspace
_G.blue()
if #_G.getTeam(game.Teams.Infected) == 0 then
begin("The round has begun.",3)
GiveGun()
FirstInfected("A player has been randomly infected!",3)
waitforwinner()
end
end
end
waitforwinner()
Thanks!
P.S. This is in a function

1 comment
I'm sorry this is tabbed and spaced badly. I've been writing as I go.