Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Put player into a random team?

I'm trying to make a script that will put the player on a random team, but I can't exactly figure it out. There are two teams, Bright red and Bright blue.

This is what I have:

local teams = {"Bright blue","Bright red"}
	for _, player in pairs(game.Players:GetChildren()) do
		player.TeamColor = player.TeamColor.new(math.random)
	end

2 answers

GIF proving this code works. http://imgur.com/Io97MhX

local Teams, Players, Nothing, Runservice ={
	{"Team1", "Really blue"};
	{"Team2", "Really red"};
}, game:GetService("Players"), math.randomseed(tick()), game:GetService("RunService")

function change_teams()
	for _,p in next,Players:GetPlayers() do
		local cTeam  		=Teams[math.random(1, #Teams)] -- Teams[1] or Teams[2]
		local Player 		=p
		Player.TeamColor	=BrickColor.new( cTeam[2] ) -- cTeam[2] = a color
		print(p.Name.."'s name is now "..cTeam[1])
	end
end

if Runservice:IsStudio() then
	print("Your in studio! I need to wait until the game is done loading!")
	repeat wait() until game.Loaded
	workspace:WaitForChild(game.Players.LocalPlayer.Name)
end

print("Game loaded! I will start my loop!")

while true do
	change_teams()
	wait(5)
end

2 comments

0

Messor you still go on this website? WHAT?!

0

Yes

function auto()

P  = game.Players
NumP = game.Players.NumPlayers

for _, red in pairs(P:GetPlayers()) do
numred = red[math.random(1,NumP)]
numred.TeamColor = BrickColor.new("Bright red")
end

for _, blue in pairs(P:GetPlayers()) do
if blue.TeamColor ~= BrickColor.new("Bright red") then
blue.TeamColor = BrickColor.new("Bright blue")
end
end
end

This discussion is preserved as it was. New answers, comments, and votes are closed.