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

Putting Players in a Team With A Max Limit?

Okay, so I'm making a game with 2 teams. Those teams have a max of four people. How do I make it so that the playercount doesn't go over that max?

1 answer

✓ Accepted answer

I want you to try writing this script before I offer any more help on this, but I am going to give you a few tools to get you started.

GetPlayers() is a function of Players and returns a table (basically a list) of all Players in the game.

TeamColor is the property of Player you should be using to assign a player to a new team.

You should create a table for each team and use table.insert() to insert the name of each player inside that team. This can be used for later things down the road in the script, but for now you can use #TABLE_NAME to get the number of things in the table. You can use the following to check if a team already has the max amount of players:

local team1 = {}
local team2 = {}

	-- Insert a few Players into the teams

if #team1 == 4 then
	-- Make sure you don't add any more players
end

To randomly assign people, you can use random numbers. Before using math.random() though, you should use math.randomseed. More on that, here.

Here is an example seeder I use for when I want to generate a completely random number each time:

local seeder = coroutine.create( function()
	while true do 
		math.randomseed( tick() )
		coroutine.yield() 
	end
end)

-- Any time you are about to use math.random, call the following:
coroutine.resume(seeder)

1 comment

0

Although I didn't see it until now- this helped!

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