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

Team wins if other team has zero players ?

Asked by 6 years ago
Edited 6 years ago

Hi, I am making a game where 1 player is chosen as a zombie and the rest are survivors.I am almost done with the scripting but I have one problem How do I check the number of players on the survivor team and if it is zero it does something.I only need a way to check the number of players nothing else

I made this code by using a free model for the intermission and following tutorials

local status = game.ReplicatedStorage:WaitForChild("Status")

while true do status.Value = "Intermission!" wait(5)

function setTeam(player, Spectator)
    player.TeamColor = game.Teams[Spectator].TeamColor
    if player.Character then --Just in case the character doesn't exist for some reason
        player.Character:BreakJoints() -- Kills the players' character
    end
end

--Changing everyone's team to "Reds"
for _, player in pairs(game.Players:GetPlayers()) do
    setTeam(player, "Spectator")
end

local randomPlayer = game.Players:GetPlayers()[math.random(1,#game.Players:GetPlayers())]
randomPlayer.TeamColor = BrickColor.new("Camo")

p = game.Players:GetChildren()
for i = 1,#p do
p[i].Character.Head:remove()
end

status.Value = "Round in Progress"
wait(120)

function setTeam(player, Spectator) player.TeamColor = game.Teams[Spectator].TeamColor if player.Character then --Just in case the character doesn't exist for some reason player.Character:BreakJoints() -- Kills the players' character end end

--Changing everyone's team to "Reds" for _, player in pairs(game.Players:GetPlayers()) do setTeam(player, "Spectator") end status.Value = "Game Over!" wait(5) end

1 answer

Log in to vote
1
Answered by 6 years ago

Use this function

local function getPlayerFromTeamColor(color)
    local players={}
    for ind, player in pairs(game("GetService","Players"):GetPlayers()) do
        print(player.TeamColor)
        if player.TeamColor==BrickColor.new(color) then
            table.insert(players,player)
        end
    end
    return #players
end


print(getPlayerFromTeamColor("White")) -- Returns the number of players that match this TeamColor

Ad

Answer this question