generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Determine Number Of Players In A Team?

Previous Thread :: Next Thread 
EgoRenascitur is not online. EgoRenascitur
Joined: 17 Nov 2013
Total Posts: 1049
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
COOLDUDE11OO is not online. COOLDUDE11OO
Joined: 21 Aug 2011
Total Posts: 5115
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
EgoRenascitur is not online. EgoRenascitur
Joined: 17 Nov 2013
Total Posts: 1049
28 Mar 2014 10:50 PM
@Cool

The counting part is what I need though.
Report Abuse
BladeXE is not online. 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
EgoRenascitur is not online. EgoRenascitur
Joined: 17 Nov 2013
Total Posts: 1049
28 Mar 2014 11:20 PM
Thanks for the help, Blade.
Report Abuse
EgoRenascitur is not online. EgoRenascitur
Joined: 17 Nov 2013
Total Posts: 1049
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 is not online. BladeXE
Joined: 22 Dec 2012
Total Posts: 3857
28 Mar 2014 11:25 PM
^
I'm guessing mine failed..
Report Abuse
cntkillme is not online. 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 is not online. BladeXE
Joined: 22 Dec 2012
Total Posts: 3857
28 Mar 2014 11:28 PM
Did mine fail, or no
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
28 Mar 2014 11:29 PM
Yes yours would of failed
Report Abuse
BladeXE is not online. BladeXE
Joined: 22 Dec 2012
Total Posts: 3857
28 Mar 2014 11:30 PM
^
What did I do wrong?
Report Abuse
cntkillme is not online. 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
EgoRenascitur is not online. EgoRenascitur
Joined: 17 Nov 2013
Total Posts: 1049
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 is not online. 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 is not online. 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 is not online. 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 is not online. L0cky2013
Joined: 30 Jul 2012
Total Posts: 1446
28 Mar 2014 11:38 PM
red, blue=getPlayersonTeam()
print(tostring(red), tostring(blue))
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image