Hi, I'm trying to find a way to divide the amount of given players in half when placing them on certain teams.
This is my code:
1 | local player = game.Players:GetPlayers() |
2 | [ math.random( 2 ,#game.Players:GetPlayers()) ] |
3 | player.TeamColor = BrickColor.new( "Bright green" ) |
As you can see, the obvious issue is that if the game only had 2 players, they'd both be on one team. I'm not sure how to do this, so any help is greatly appreciated.
Hey, I have made the script for you. If you have any questions, please ask me.
01 | --Get the Player count |
02 | local playercount = #game.Players:GetChildren() |
03 |
04 | --Calculate how many players should go on the team |
05 | --Is the number even? |
06 | if playercount % 2 = = 0 then |
07 | --number is even |
08 | local playersselected = 0 |
09 | local toselectplayers = playercount / 2 |
10 | for i, v in pairs (game.Players:GetChildren()) do |
11 | if playersselected < toselectplayers then |
12 | v.Neutral = false |
13 | v.TeamColor = BrickColor.new( "Bright green" ) |
14 | playersselected = playersselected + 1 |
15 | end |