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

How would I get this script to change operations when # of players on a team changes?

Asked by 9 years ago

So I'm using this script to determine how many players on a team. It works fine, except I want the script to tell if the number of people on a team changes, and then reacts to that. Can someone please help me?

Here's the script

local team = game.Teams;

function getPlayers(teamColor)
    local found = { };
    for _,v in pairs(game.Players:GetPlayers()) do
        if v.TeamColor == teamColor then
            table.insert(found, v)
        end
    end
    return #found
end

while wait() do
    local greenNum = getPlayers(BrickColor.new('Bright green'))
    local redNum = getPlayers(BrickColor.new('Bright red'))
    if greenNum > 0 and redNum > 0 then
        print('Enough players')
    else
        print('Not enough players')
    end
end

0
That would work perfectly, and DONT double post. And before you ask, YES it would react if one of the teams' number of members went below 1 Goulstem 8144 — 9y
0
It's not working. I'm testing it on online. I had both teams have 0, it printed the message, and now that both teams have at least one person, the script from when they didn't have any people isn't reacting to the change. I'm sorry for double posting CoolJohnnyboy 121 — 9y

Answer this question