Team randomiser

So I have a training facility.
We run events , do competitions etc.
But it’s hard to do when we can’t organise the teams quickly and efficiently.

If someone could point me in a direction to make a script for this.

I can take either a Nexus admin format or a GUI button format.
Preferably nexus admin as we do use a customised module and it would work better for batch cmds

Discord:
Emerald#1452

1 Like

Do you have a Roblox group? If you do, you can put a script which auto-assigns each rank to a specific role. Hang on, I’ll find the script right now.

1 Like

Not what I mean.
What I mean is when the button is pressed//when the command is run
it sorts the selected players/team onto the chosen teams

Ah, okay. I get you. That would be cool but I do not know how to do it. :confused: Good luck though!

Thanks , I’ve searched far and wide for a solution and found nothing soo , here I come devforum

local teams = game:GetService("Teams"):GetTeams() -- or whatever teams you want to be randomized
for i, player in pairs(game.Players:GetPlayers()) do
	player.TeamColor = teams[1 + (i % #teams)].TeamColor
end

So would I link that to a button or?

Hope you find a solution soon! :pray:

You can do a table with all the players and then simply do something like this:

-- For 2 teams.
local players = game.Players:GetPlayers()
local teamService = game:GetService("Teams")
local firstTeam
local secondTeam
--First team
for i = 1, math.floor(#players/2) do
      firstTeam = Instance.new("Team", teamService)
      firstTeam.TeamColor = BrickColor.new("Bright red")
      players[i].TeamColor = firstTeam.TeamColor
end
--Second team
for i = math.floor(#players/2) + 1, #players do
      secondTeam = Instance.new("Team", teamService)
      secondTeam.TeamColor = BrickColor.new("Bright blue")
      players[i].TeamColor = secondTeam.TeamColor
end

Note that I divided the number of players by 2 so I can do a balanced 2 teams but if there is a ammount like 7 then a team will have only 1 player more than the other thats why i floored it.

I add 1 to the number of players divided by 2 in the second loop just so I can get the next player.

This is the script you would use to actually randomize the teams. How you want to send that command is up to you. You can link it to a GUI button, but then you would need to use a RemoteEvent to run the code on the server, as well as perform some checks for security. I won’t write the entire system, because again its up to you in the end, but it would look something like this:

-- Client
TextButton.MouseButton1Click:Connect(function()
     RemoteEvent:FireServer()
end)
-- Server
local teams = game:GetService("Teams"):GetTeams() -- or whatever teams you want to be randomized

RemoteEvent.onServerEvent:Connect(function(player)
     if playerHasAccess() then -- make sure player has access to randomize teams (prevents exploiters)
          for i, player in pairs(game.Players:GetPlayers()) do
	          player.TeamColor = teams[1 + (i % #teams)].TeamColor
          end
     end
end)