Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why won't this recognize the script?(unanswered)

Asked by
wjs3456 90
9 years ago

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

0
What exactly happens that shouldn't? GoldenPhysics 474 — 9y
0
No message appears wjs3456 90 — 9y
0
That will only run once. Lacryma 548 — 9y
0
I know there is a separate part that renames the functions in order. Will it continuously check? wjs3456 90 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

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
Ad

Answer this question