Kasumo
|
  |
| Joined: 22 Mar 2013 |
| Total Posts: 2467 |
|
|
| 25 Jul 2014 01:54 PM |
How do I get how many players are on the team when gT hits 0? And the team with the most players in it wins?
if (gT.Value == 0) then p[i].Character.Humanoid.Health = 0 --Instance.new("Message",game.Workspace).Text = " team has won!"-- end end |
|
|
| Report Abuse |
|
|
Kasumo
|
  |
| Joined: 22 Mar 2013 |
| Total Posts: 2467 |
|
| |
|
|
| 25 Jul 2014 02:11 PM |
You could try using something such as, TeamCount = 0 for _,v in pairs(game.Players:GetPlayers()) do if v.TeamColor == game.Teams.TeamNameHere.TeamColor then TeamCount = TeamCount+1 end end |
|
|
| Report Abuse |
|
|
Kasumo
|
  |
| Joined: 22 Mar 2013 |
| Total Posts: 2467 |
|
| |
|
|
| 25 Jul 2014 02:32 PM |
The script loops through the Player's table and increases the numerical value of the variable "TeamCount" for each player matching the team's TeamColor.
You could create two separate variables for each team and then use conditional statements to compare the resulting value of both variables. |
|
|
| Report Abuse |
|
|
|
| 25 Jul 2014 02:39 PM |
-- I made this earlier today for a different question.
_G.GetPlayersOnTeam = function(name) local plrs = {}; if(game.Teams:FindFirstChild(name)) then local team = game.Teams[name]; for index,value in next,game.Players:GetPlayers() do if(value.TeamColor == team.TeamColor) then table.insert(plrs, value); end end end end
USAGE FROM ANY SCRIPT
print(tostring(#_G.GetPlayersOnTeam("team name here")));
USAGE TO GET PLAYERS FROM ANY SCRIPT TO OUTPUT
print(unpack(_G.GetPlayersOnTeam("team name here")));
|
|
|
| Report Abuse |
|
|
|
| 25 Jul 2014 02:43 PM |
-- Oh, and usage in this specific case : repeat wait() until gT.Value == 0; numplayers = tostring(#_G.GetPlayersOnTeam("team name here"));
|
|
|
| Report Abuse |
|
|
|
| 25 Jul 2014 02:47 PM |
@KOT and what if the script uses the _G function before the script that creates the _G function loads?
Uh oh *game breaks* |
|
|
| Report Abuse |
|
|
| |
|
|
| 25 Jul 2014 02:48 PM |
@sens
It what world would that work? |
|
|
| Report Abuse |
|
|
|
| 25 Jul 2014 02:50 PM |
@war; no clue why people keep saying #TEAM:GetChildren(). ever since you left, this place has been filled with trolls. and good point about the game breaking thing.
this is a signature: pcall(function() print([[apparently this is a string]]) end) |
|
|
| Report Abuse |
|
|
|
| 25 Jul 2014 02:53 PM |
GetChildren() returns a table
#table = number |
|
|
| Report Abuse |
|
|
|
| 25 Jul 2014 02:54 PM |
"ever since you left"
When'd I leave? XD
Yea #TEAM:GetChildren() is like the worst attempt ever. |
|
|
| Report Abuse |
|
|
|
| 25 Jul 2014 02:57 PM |
@sen; the players aren't stored within the team. *facedesk*
this is a signature: pcall(function() print([[apparently this is a string]]) end) |
|
|
| Report Abuse |
|
|
| |
|
| |
|