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 7 years ago
Edited 7 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)

01function setTeam(player, Spectator)
02    player.TeamColor = game.Teams[Spectator].TeamColor
03    if player.Character then --Just in case the character doesn't exist for some reason
04        player.Character:BreakJoints() -- Kills the players' character
05    end
06end
07 
08--Changing everyone's team to "Reds"
09for _, player in pairs(game.Players:GetPlayers()) do
10    setTeam(player, "Spectator")
11end
12 
13local randomPlayer = game.Players:GetPlayers()[math.random(1,#game.Players:GetPlayers())]
14randomPlayer.TeamColor = BrickColor.new("Camo")
15 
View all 22 lines...

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 7 years ago

Use this function

01local function getPlayerFromTeamColor(color)
02    local players={}
03    for ind, player in pairs(game("GetService","Players"):GetPlayers()) do
04        print(player.TeamColor)
05        if player.TeamColor==BrickColor.new(color) then
06            table.insert(players,player)
07        end
08    end
09    return #players
10end
11 
12 
13print(getPlayerFromTeamColor("White")) -- Returns the number of players that match this TeamColor
Ad

Answer this question