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

My team randomizer is not working like it should. How would I fix the issue?

Asked by 4 years ago

Hello First off this is a alt account. That is why bacon hair. Moving on

view source

01  local teams = game:GetService("Teams")
02  local tInfo = {
03      ["Stalker"] = {
04          MaxPlayers = 1;
05      },
06      ["Survivor"] = {
07          MaxPlayers = 9;
08      },
09      ["Spectator"] = {
10          MaxPlayers = 10;
11      }
12    }
13  local function countTeam(team)
14      local count = 0
15      for _, player in next, players:GetPlayers() do
16          if player.Team == team then
17              count = count + 1
18          end
19      end
20      return count
21  end
22   
23  local function assignRandomTeam(player)
24      local assigned = false
25      while not assigned do
26          local randomTeam = teams:GetChildren()[math.random(1,#teams:GetChildren())]
27          if randomTeam and countTeam(randomTeam) < tInfo[randomTeam.Name].MaxPlayers
28  then
29              player.Team = randomTeam
30              assigned = true
31          end
32          wait(.5)
33      end
34  end

This the current code i have. I found it on a dev forum. (Cant find it again). The first part of it is how mant people are limited to a team. The secound part (The issue) is i want to to randomly assign player's to a team. For example i want 1 person to be the stalker and others to be survivors. When i load my game it automatically loads me to the Neutral team.I have no Neutral team under my team menu so it creates it because it has no team. I have ran and ran it to see if it was bad luck but i has always been neutral. I am new to code so i may not know what you mean. Thank you

0
try adding `game.Players.PlayerAdded:Connect(assignRandomTeam)` to the last line Leamir 3138 — 4y
0
Didnt work i added it at line 31 moving the end down but it did not work toxitman2account -7 — 4y

Answer this question