Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Putting Players in a Team With A Max Limit?

Asked by 8 years ago

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

Log in to vote
0
Answered by
Validark 1580 Snack Break Moderation Voter
8 years ago

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)
0
Although I didn't see it until now- this helped! iiDitzy 5 — 8y
Ad

Answer this question