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 » Scripters
Home Search
 

Re: Script that reacts when the # of players on team changes

Previous Thread :: Next Thread 
CoolJohnnyboy is not online. CoolJohnnyboy
Joined: 09 Mar 2010
Total Posts: 17699
25 Apr 2015 05:17 PM
So I'm using this script to determine how many players on a team. It works fine, except that when the number of people on either one of the two teams changes, the script does not react like I want it to.

Here's the script

local team = game.Teams;

function getPlayers(teamColor)
local found = { };
for _,v in pairs(game.Players:GetPlayers()) do
if v.TeamColor == teamColor then
table.insert(found, v)
end
end
return #found
end

while wait() do
local greenNum = getPlayers(BrickColor.new('Bright green'))
local redNum = getPlayers(BrickColor.new('Bright red'))
if greenNum > 0 and redNum > 0 then
print('Enough players')
else
print('Not enough players')
end
end

Report Abuse
tecno15 is not online. tecno15
Joined: 10 Sep 2009
Total Posts: 1372
25 Apr 2015 05:19 PM
a while wait() loop

how adorable
Report Abuse
nQqzRYVpIKA5jLP is not online. nQqzRYVpIKA5jLP
Joined: 05 Mar 2015
Total Posts: 4135
25 Apr 2015 05:20 PM
Well how do you want it to react?
Report Abuse
CoolJohnnyboy is not online. CoolJohnnyboy
Joined: 09 Mar 2010
Total Posts: 17699
25 Apr 2015 05:25 PM
When it detects that there is 0 players on one or the other team (or both), it prints "Not enough players"

I want the script to do is detect if the number of players on the team changes, and if it does, to both teams having a minimum of one player, I want it to print "Enough players"
Report Abuse
CoolJohnnyboy is not online. CoolJohnnyboy
Joined: 09 Mar 2010
Total Posts: 17699
25 Apr 2015 07:38 PM
bump
Report Abuse
LuminaDeVis is not online. LuminaDeVis
Joined: 14 Apr 2013
Total Posts: 34
25 Apr 2015 08:07 PM
wiki.roblox.com/index.php?title=Teams#Events
ChildAdded and ChildRemoved might be of help here
Report Abuse
CoolJohnnyboy is not online. CoolJohnnyboy
Joined: 09 Mar 2010
Total Posts: 17699
25 Apr 2015 11:19 PM
The script works fine, I just need it to react when values change
Report Abuse
CoolJohnnyboy is not online. CoolJohnnyboy
Joined: 09 Mar 2010
Total Posts: 17699
26 Apr 2015 10:35 AM
b2
Report Abuse
acidflip is not online. acidflip
Joined: 18 Jul 2012
Total Posts: 886
26 Apr 2015 10:37 AM
> "The script works fine, I just need it to react when values change"

and this is how you do that:
http://www.roblox.com/Forum/ShowPost.aspx?PostID=160960403#160946451
Report Abuse
CoolJohnnyboy is not online. CoolJohnnyboy
Joined: 09 Mar 2010
Total Posts: 17699
26 Apr 2015 11:01 AM
b3
Report Abuse
CoolJohnnyboy is not online. CoolJohnnyboy
Joined: 09 Mar 2010
Total Posts: 17699
26 Apr 2015 11:57 AM
b4
Report Abuse
CoolJohnnyboy is not online. CoolJohnnyboy
Joined: 09 Mar 2010
Total Posts: 17699
26 Apr 2015 12:24 PM
bump
5
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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