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:
local player = game.Players:GetPlayers() [math.random(2,#game.Players:GetPlayers())] 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.
--Get the Player count local playercount = #game.Players:GetChildren() --Calculate how many players should go on the team --Is the number even? if playercount % 2 == 0 then --number is even local playersselected = 0 local toselectplayers = playercount / 2 for i, v in pairs(game.Players:GetChildren()) do if playersselected < toselectplayers then v.Neutral = false v.TeamColor = BrickColor.new("Bright green") playersselected = playersselected + 1 end end else --number is odd local playersselected = 0 local toselectplayers = playercount / 2 + 0.5 for i, v in pairs(game.Players:GetChildren()) do if playersselected < toselectplayers then v.Neutral = false v.TeamColor = BrickColor.new("Bright green") playersselected = playersselected + 1 end end end