What I want to do is:
Assign a certain percentage of players to the Red team
Assign a certain percentage of players to the Blue team
Assign the rest to the yellow team
If I can't do percentages then I would like to just manually setup it like this:
1 | if numofplayers = = 3 then |
2 |
3 | --assign one player to red |
4 |
5 | --assign one player to blue |
6 |
7 | --assign the rest to yellow |
8 |
9 | end |
etc.
Any help?
edit: I messed up the math in the percentage. Also tested the code this time, it should work. change percentage table to change the percentage of people in each team.
I did this for one of my games, I didn't test the code yet so let me know if it doesn't work assuming you have the teams as RedTeam BlueTeam YellowTeam Also this assumes there is at least 3 people in the server
01 | Players = game:GetService( "Players" ) |
02 |
03 | blueteam = game.Teams.BlueTeam |
04 | yellowteam = game.Teams.YellowTeam |
05 | redteam = game.Teams.RedTeam |
06 | percentage = { blue = . 05 ,red = . 05 , yellow = . 90 } -- this has to equal 1,currently 5% of people will be in blue 5% in red 90% in yellow |
07 |
08 | function AssignTeams() -- assumes more than 3 players |
09 | local playerlist = Players:GetPlayers() -- get players |
10 | local totalplayers = #playerlist -- total players |
11 | local redpercent = math.ceil(totalplayers * percentage.red) -- calculate red team |
12 | local bluepercent = math.ceil(totalplayers * percentage.blue) -- calculate blue team |
13 | local i = redpercent |
14 | while i > 0 do |
15 | playerlist [ i ] .Team = redteam |
Did some of my own scripting and fixed it myself:
01 | local plrs = game.Players:GetPlayers() |
02 |
03 |
04 | for i, plr in pairs (plrs) do |
05 | local p = i/#plrs |
06 | if p < 0.4 then -- 40% |
07 |
08 | plr.Team = game.Teams.RedTeam |
09 | plr.Character.Humanoid.Health = 0 |
10 |
11 | elseif p < 0.4 then -- 40% |
12 |
13 | plr.Team = game.Teams.BlueTeam |
14 | plr.Character.Humanoid.Health = 0 |
15 |