|
| 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 |
|
|
|
| 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 |
|
|
|
| 30 Sep 2014 12:55 AM |
| Okay thanks! I will try it out in the evening! |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|