Answer: You never updated the number of players during the loop / You did not give your loop an exit when the desired condition was met / You did not call the function to start it
Fix:
local SpecTeam = game.Teams.Spectating:GetPlayers()
function CheckForPlayers()
SpecTeam = game.Teams.Spectating:GetPlayers()
while wait(0.5) do
if #SpecTeam >= 2 then
InRound.Value = true
break
end
end
end
CheckForPlayers()
More explanation: When you initialized the variable SpecTeam you set it to the value of the current players in the session (0 players, assuming the script is loaded immediately when the game starts). And you did not update the value in your loop at all. Therefore SpecTeam will remain as an empty table indefinitely. In addition to this problem you didn't provide a way for the loop to exit when your desired outcome has been reached.
Note: If you're going to copy my code, please hit "View Source" to copy it correctly.
Optimization: (A better way to do what you're doing)
function CheckForPlayers()
repeat wait(0.5)
until #game.Teams.Spectating:GetPlayers() >= 2
InRound.Value = true
return
end
CheckForPlayers()
2 comments
Are you getting an error from this?
no