|
| 28 Mar 2014 09:35 PM |
| If I wanted a script to recognize the amount of players in a team, how would I do so? I can't even take a decent guess at this. |
|
|
| Report Abuse |
|
|
|
| 28 Mar 2014 09:59 PM |
red = { } blue = { }
game.Players.PlayerAdded:connect(function(plr) if plr.TeamColor == BrickColor.new("Bright red") then table.insert(red,plr.Name) elseif plr.TeamColor == BrickColor.new("Bright blue") then table.insert(blue,plr.Name) end end)
And some other method to count something in a table. |
|
|
| Report Abuse |
|
|
|
| 28 Mar 2014 10:50 PM |
@Cool
The counting part is what I need though. |
|
|
| Report Abuse |
|
|
BladeXE
|
  |
| Joined: 22 Dec 2012 |
| Total Posts: 3857 |
|
|
| 28 Mar 2014 11:15 PM |
players = game.Players:GetChildren() if players.Teamcolor == "Bright red" then players = "reds" else players = "blues" print(#reds) print(#blues) |
|
|
| Report Abuse |
|
|
|
| 28 Mar 2014 11:20 PM |
| Thanks for the help, Blade. |
|
|
| Report Abuse |
|
|
|
| 28 Mar 2014 11:24 PM |
So, would this script work out correctly?
My Attempt:
plr = game.Players:GetChildren()
game.Players.PlayerAdded:connect(function(player) if script.Parent.Override ~= true then if plr.TeamColor == "Bright Red" then plr = "Xhelight" else plr = "Other" if (#Xhelight) == 5 then script.Parent.Regular = false end end end end) |
|
|
| Report Abuse |
|
|
BladeXE
|
  |
| Joined: 22 Dec 2012 |
| Total Posts: 3857 |
|
|
| 28 Mar 2014 11:25 PM |
^ I'm guessing mine failed.. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 28 Mar 2014 11:27 PM |
local countByColor = {}
for index, value in next, Game.Players:GetPlayers() do if not value.Neutral then countByColor[tostring(value.TeamColor)] = (countByColor[tostring(value.TeamColor)] or 0) + 1 end end |
|
|
| Report Abuse |
|
|
BladeXE
|
  |
| Joined: 22 Dec 2012 |
| Total Posts: 3857 |
|
| |
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
| |
|
BladeXE
|
  |
| Joined: 22 Dec 2012 |
| Total Posts: 3857 |
|
| |
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 28 Mar 2014 11:32 PM |
1) Attempted to index 'Teamcolor' on a numerical-key based table 2) If you did loop correctly, it would be TeamColor which is equal to a BrickColor value, not string 3) You set the table to a string 4) You got the length of a string, not of everyone who 'got added' which you didn't do. |
|
|
| Report Abuse |
|
|
|
| 28 Mar 2014 11:34 PM |
@cnt
I don't really understand how your script works, could you explain it a bit to me? |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 28 Mar 2014 11:35 PM |
local countByColor = {} --I created a table
for index, value in next, Game.Players:GetPlayers() do --I loop through all the players
if not value.Neutral then --I make sure they aren't neutral
countByColor[tostring(value.TeamColor)] = (countByColor[tostring(value.TeamColor)] or 0) + 1 --set the value of countByColor["The Color as a string, not as a BrickColor value"] equal to itself (if it doesn't exist, set it to 0) plus 1
end end |
|
|
| Report Abuse |
|
|
L0cky2013
|
  |
| Joined: 30 Jul 2012 |
| Total Posts: 1446 |
|
|
| 28 Mar 2014 11:38 PM |
function getPlayersonteam() red={}; blue={}; for _, v in pairs(game:service'Players':GetPlayers()) do if v.TeamColor==BrickColor.new('Really red') then table.insert(red, v) elseif v.TeamColor==BrickColor.new('Really blue') then table.insert(blue, v) end end return #red, #blue end
red, blue=getPlayersonTeam print(tostring(red), tostring(blue)) |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 28 Mar 2014 11:38 PM |
| You don't need to tostring it btw. |
|
|
| Report Abuse |
|
|
L0cky2013
|
  |
| Joined: 30 Jul 2012 |
| Total Posts: 1446 |
|
|
| 28 Mar 2014 11:38 PM |
red, blue=getPlayersonTeam() print(tostring(red), tostring(blue))
|
|
|
| Report Abuse |
|
|