Random Team Picker

How can I make all players get an automatic random team Not all the same but all different Team names:

Team 1 / Team 2.

Script:

local B2 = script.Parent.STOP
local TEAMS = game:GetService("Teams"):GetTeams()

-- START SCRIPT
B1.MouseButton1Click:Connect(function()
		local T1 = Instance.new("Team")
		T1.Parent = game.Teams
		T1.Name = "Team 1"
		T1.TeamColor = BrickColor.new("Gold")
		local T2 = Instance.new("Team")
		T2.Parent = game.Teams
		T2.Name = "Team 2"
		T2.TeamColor = BrickColor.new("Pink")
end)

Just to make sure, you want each player to be on their own team? Or just separated between two teams?

Yes, in his own team indeed and then divided over 2 teams.

So like, someone would be on their own team, but also on red or blue?

Well just that they either come in team 1 or in team 2 when the button is clicked.

Try this:

local B2 = script.Parent.STOP
local players = game:GetService("Players"):GetPlayers()

local teams = {"Team 1", "Team 2"}

local function giveRandomTeam()
       for i = #players, 2, -1 do
           local j = math.random(i)
           players[i], players[j] = players[j], players[i]
       end
       for i, player in ipairs(players) do
           player.Team = game:GetService("Teams")[teams[i % 2 + 1]]
       end
end

B1.MouseButton1Click:Connect(function()
		local T1 = Instance.new("Team")
		T1.Parent = game.Teams
		T1.Name = "Team 1"
		T1.TeamColor = BrickColor.new("Gold")
		local T2 = Instance.new("Team")
		T2.Parent = game.Teams
		T2.Name = "Team 2"
		T2.TeamColor = BrickColor.new("Pink")
        giveRandomTeam()
end)

I think he wants the players to join a random team whenever they click, not all the players to be assigned to teams at once.

local T1 = Instance.new("Team")
T1.Parent = game.Teams
T1.Name = "Team 1"
T1.TeamColor = BrickColor.new("Gold")
local T2 = Instance.new("Team")
T2.Parent = game.Teams
T2.Name = "Team 2"
T2.TeamColor = BrickColor.new("Pink")

B1.MouseButton1Click:Connect(function()
	local team = math.random(1, 2)
    if team % 2 == 0 then
        game.Players.LocalPlayer.Team = B2
    else
        game.Players.LocalPlayer.Team = B1
    end
end)

This will put them on random teams, which means it may not be equal!!!
If you want them to be equal:

local T1 = Instance.new("Team")
T1.Parent = game.Teams
T1.Name = "Team 1"
T1.TeamColor = BrickColor.new("Gold")
local T2 = Instance.new("Team")
T2.Parent = game.Teams
T2.Name = "Team 2"
T2.TeamColor = BrickColor.new("Pink")

B1.MouseButton1Click:Connect(function()
    if #B2:GetPlayers() < #B1:GetPlayers() then
        game.Players.LocalPlayer.Team = B2
    else
        game.Players.LocalPlayer.Team = B1
    end
end)

The above should sort them into teams based on which one has less players, might result in an error because I haven’t tested it.

He said all players but yeah, he maybe meant that.

I think what he’s trying to do is have a button that the player clicks which puts them on a random team.

Yup thanks, this works for me and its good.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.