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

Adding players to a random team?

I want all players to teleport to 2 random teams. Where should I begin in this script? If so, an example would be helpful for me.

local GameTime = 10
local text = script.Text

while true do
	wait(5)
	text.Value = "Intermission..."
	print("Intermission...")
	wait(1)
	local RandomNumber = math.random(1, 1)
	local Map = game.ServerStorage["Map".. RandomNumber]
	
	Map:Clone().Parent = workspace.MapFolder
	
	ftime = GameTime
	
	local SpawnCount = Map.SpawnCount
	
	wait(5)
	
	for _, v in pairs(game.Players:GetChildren())do
 		Player = Instance.new("StringValue",workspace.Players)
 		Player.Name = v.Name
 		randomN = math.random(1, SpawnCount.Value)
 		v.Character.Torso.CFrame = CFrame.new(Map["Spawn"..randomN].Position+Vector3.new(0,3,0))
 	end

1 answer

✓ Accepted answer

to split the players into teams, you can do the following:

teams = {TeamInstanceHere,TeamInstanceHere}
local current = 1

for _,v in pairs(game.Players:GetChildren()) do
	v.Team = teams[current]
	if current == #teams then
		current = 1
	else
		current = current+1
	end
end

This will split the players evenly between any team instances in the table "Teams". With further questions/comments/concerns, feel free to reply! Happy sccripting! ~mc3334

3 comments

0

Thank you! I'll look into the script and let you know if it's working.

0

I'm getting an error on line 05. Workspace.Main Script:32: bad argument #3 to 'Team' (Object expected, got string)

0

Nevermind, I got it.

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