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: Putting players in 2 teams.

Previous Thread :: Next Thread 
BirdBoy146 is not online. BirdBoy146
Joined: 25 Sep 2011
Total Posts: 39
29 Sep 2014 02:52 PM
I want the players to teleport too a map and then put half of the teleported players inside the blue team and half of the players inside the red team. But I don't know how to put the players inside the teams. Does anyone know how to do this?
Report Abuse
Ethancomputermad is not online. Ethancomputermad
Joined: 22 Feb 2010
Total Posts: 533
29 Sep 2014 03:51 PM
Heres some code I wrote up, change as appropriate:

game:GetService('Teams')

team_a=game.Teams['Red Team']
team_b=game.Teams['Blue Team']

plrs=game.Players:GetPlayers()

for i=1, #plrs do

if i>#plrs/2 then
plrs[i].TeamColor=team_b.TeamColor

else

plrs[i].TeamColor=team_a.TeamColor
end

end
Report Abuse
BirdBoy146 is not online. BirdBoy146
Joined: 25 Sep 2011
Total Posts: 39
30 Sep 2014 12:55 AM
Okay thanks! I will try it out in the evening!
Report Abuse
BirdBoy146 is not online. BirdBoy146
Joined: 25 Sep 2011
Total Posts: 39
30 Sep 2014 08:58 AM
Okay so this actually works! But the only problem is the teams wont change if you are with the same players. For example what you now have is:
There are 4 players in the game they are called Player1, Player2, Player3 and Player4. Player 1 & 2 will always be putten in team blue and player3 & 4 will always be red. I want this to be randomized so one time Player 3&2 are in team blue and player1 & 4 are in red and the next game maby are PLayer1 & 3 in blue and Player 2&4 in red.
Report Abuse
BJCarpenter is not online. BJCarpenter
Joined: 04 Nov 2008
Total Posts: 4416
30 Sep 2014 11:57 AM
Just making this up, so it WILL contain errors:


math.randomseed(tick())

game:GetService('Teams')

team_a=game.Teams['Red Team']
team_b=game.Teams['Blue Team']

plrs=game.Players:GetPlayers()

for i=1, #plrs do

--if i>#plrs/2 then
if math.random()>.5 then

plrs[i].TeamColor=team_b.TeamColor

else

plrs[i].TeamColor=team_a.TeamColor
end

end



Report Abuse
BJCarpenter is not online. BJCarpenter
Joined: 04 Nov 2008
Total Posts: 4416
30 Sep 2014 12:03 PM
ok,

realized ur gonna want even teams: For me five more lines of code.

Better: Roblox already has a Team sorting method.

Go here:

http://wiki.roblox.com/index.php/Function_Dump/Mathematical_Functions

Type in "Teams", and become The Expert in 'Teams'.
Report Abuse
BirdBoy146 is not online. BirdBoy146
Joined: 25 Sep 2011
Total Posts: 39
01 Oct 2014 09:24 AM
I think I fixed it by doing this no errors found yet so I think it fully works.:
math.randomseed(tick())
game:GetService('Teams')

local teamred = game.Teams:WaitForChild("Red")
local teamblue = game.Teams:WaitForChild("Blue")

local plrs = game.Players:GetPlayers()
local teamcounterblue = 0
local teamcounterred = 0
local playershalf = #plrs / 2

for i=1, #plrs do
if math.random()>.5 then
if teamcounterblue >= playershalf then
teamcounterred = teamcounterred + 1
plrs[i].TeamColor = teamred.TeamColor
else
teamcounterblue = teamcounterblue + 1
plrs[i].TeamColor = teamblue.TeamColor
end

else
if teamcounterred >= playershalf then
teamcounterblue = teamcounterblue + 1
plrs[i].TeamColor = teamblue.TeamColor
else
teamcounterred = teamcounterred + 1
plrs[i].TeamColor=teamred.TeamColor
end
end
end
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