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

How do I use this script?

Asked by
wjs3456 90
10 years ago

Someone gave me a script to fix this line:

if game.Teams.Survivors:GetPlayers() == nil then

Here is the script:

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

I have not idea what it means though and where to put it. Thanks!

1 answer

Log in to vote
3
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

getTeam is function which takes in a team, which is presumably a Team object (especially since we ask for its TeamColor in line 06).

It returns teamPlayers, which from line 03 we see is a list, and from line 06 we can see contains Player objects.

From this, we can gather than getTeam returns a list of players on a given a Team object's team.


Since you were asking to get the players from a given team, that would look like this:

getTeam(game.Teams.Survivors)

However, an empty list is not nil it is just empty. We check if a list is empty by comparing its length to 0:

if #getTeam(game.Teams.Survivors) == 0 then

Thank you perci1 for noticing my typo; Game should have been game (corrected now)

I was clearly very distracted when I wrote this, my apologies. getPlayers should have been getTeam (corrected now)

0
Still doesnt seem to work...I just put that on the top line of the infected_finish wjs3456 90 — 10y
2
Blue is correct, just make sure 'game' is lower case. Perci1 4988 — 10y
0
ahhh that might help wjs3456 90 — 10y
0
it says getPlayers is a nil value wjs3456 90 — 10y
0
Alright I think you meant getTeam thanks Blue. I appreciate your help. :D wjs3456 90 — 10y
Ad

Answer this question