I have two separate pieces of script here. Basically it displays a message if the team "survivors" has no players left. It works only in single player but when I tried to play with someone who always lags it failed to work.
function getTeam(team) local players = game.Players:GetPlayers(); local teamPlayers = {}; for _, player in pairs(players) do if player.TeamColor == team.TeamColor then table.insert(teamPlayers, player); end end return teamPlayers; end
if #getTeam(game.Teams.Survivors) == 0 then m = Instance.new("Message",Workspace) m.Text = "The final survivor was infected. Once you respawn the round will begin!" wait(3) m:Destroy()
Any reasons why this wouldn't work? Thanks
If you are trying to get the total number of teamPlayers, why don't you do #teamPlayers? You could run the function right before the if statement so that teamPlayers will have a value.
such as:
getTeam(game.Teams.Survivors) if #teamPlayers == 0 then m = Instance.new("Message", Workspace) m.Text = "The final survivor was infected. Once you respawn the round will begin!" wait(3) m:Destroy() end