Hi there! I am having troubles with my team system. My team system divides the number of people equally into a number of teams. The problem is, when I have 2 teams, it somehow always autoassigns to team 1, even if there are multiple teams…
Heres the code:
if string.split(msg, " ")[2] then
local function GetTrainees()
local trainees = {}
for i, v in players:GetPlayers() do
if true then
table.insert(trainees, v)
end
end
return trainees
end
local teamnumber = string.split(msg, " ")[2]
local trainees = GetTrainees()
local teams = {}
for i = 1, teamnumber do
print(i)
local team = CreateTeam(i)
local lo = math.floor((i-1) * #trainees / teamnumber) +1
local hi = math.floor(i * #trainees / teamnumber) +1
for j = lo, hi-1 do
print(team)
trainees[j].Team = team
print(trainees[j].Team)
end
end
end
This line
print(team)
trainees[j].Team = team
print(trainees[j].Team)
prints the right team the first time, but the second time it doesn’t matter what team we’re at, it still prints team 1. It’s almost as if in the middle between assigning a player a team and it giving the player the team, the team changes back to team 1!