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

Help with splitting players into two teams?

I cant seem to get the players on the teams can anyone help? plrs is a table of players dont worry.

plrs = IsOrNotAfkTable(false)

local Red = Instance.new("Team", game:GetService("Teams"))
Red.TeamColor = BrickColor.new("Really red")
Red.Name = "Red"
local Folder = Instance.new("Folder", Red)
Folder.Name = "leaderstats"
local Hits = Instance.new("IntValue",Folder)
Hits.Name = "Hits"


local Blue = Instance.new("Team", game:GetService("Teams"))
Blue.TeamColor = BrickColor.new("Navy blue")
Blue.Name = "Blue"
local Folder = Instance.new("Folder", Blue)
Folder.Name = "leaderstats"
local Hits = Instance.new("IntValue",Folder)
Hits.Name = "Hits"

function assignTeams()
    local balanceTolerancy = math.floor(#plrs / 2)

    for i = 1, balanceTolerancy do
		-- player's indexed here will go to team1
    end

    for i,v in pairs(plrs) do
		 --check if the player is on team1, if not then assign to team2.
	end
end

1 comment

0

I have answered this question already a separate time you posted this question. Check my response there

1 answer

You can set a player’s Team or TeamColored property to change their teams. You can read this as well to know what team they’re on.

For what you put in comments you can do this:

plrs[index].Team = Red

And based on what you asked in the second comment:

if plrs[index].Team == Red then
    plrs[index].Team = Blue
end

However that second code will just move them all to Blue, if you want a balanced team, try this article: https://developer.roblox.com/en-us/articles/team-balancing

Or you can check the bottom of this page: https://developer.roblox.com/en-us/api-reference/class/Team

2 comments

0

I would try what you did. But the for the if statement couldnt you just do if not?

0

Putting it to not means it only checks players who aren’t in red even though I assigned all players to red. I recommend you take a look at the article link at the bottom of my answer (then scroll to bottom of that page).

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