First, my Script takes random teams and adds them to the Teams Service. Then it assigns the chosen Teams to variables. After that I wrote a game.Players.PlayerAdded:Connect - function. Why does it not run? Before adding the part that chooses random Teams it did run. Heres my Code:
local nan = 0
repeat
local index = math.random(1,#Teamfolder)
currentteam = Teamfolder[index]
print(currentteam.Name.." was chosen for this round.")
currentteam.Parent = game.Teams
table.remove(Teamfolder, index)
wait(1)
nan = nan+1
until nan == 5
TeamsLoaded = true
game.Teams.ChildAdded:Connect(function(Child)
if Child == game.Teams.Hunters--1
then
Hunters = game.Teams.Hunters
end
if Child ==game.Teams.Necromancers--2
then
Necromancers = game.Teams.Necromancers
end
if Child ==game.Teams.Arsonists--3
then
Arsonists = game.Teams.Arsonists
end
if Child ==game.Teams.Jesters--4
then
Jesters = game.Teams.Jesters
end
if Child ==game.Teams.Witches--5
then
Witches = game.Teams.Witches
end
if Child ==game.Teams.Seers--6
then
Seers = game.Teams.Seers
end
end)
local Teams = game.Teams:GetTeams()
local Remotes = game.ReplicatedStorage.Remotes
GameStart = game.ServerStorage.GameStarting
Neededplayers = 3 --Needed Players to start.
game.Players.PlayerAdded:Connect(function(plr) --[[I closed the function to make it less confusing. (I'll provide the code inside it below)]]
end)
Code inside function:
repeat
wait()
until TeamsLoaded == true
print("Player joined: "..plr.Name)
if #Players:GetPlayers() == Neededplayers
then
print("")
print("Enough Players: (" ..#game.Players:GetPlayers().."/"..Neededplayers..")")
print("")
print("Assigning Teams...")
for _,player in pairs(Players:GetPlayers())--For every player do:
do
local randomteam = Teams[math.random(1,#Teams)]--Get random Team.
local Full = randomteam:FindFirstChildWhichIsA("IntValue")--Get IntValue inside the randomteam.
if #randomteam:GetPlayers() < Full.Value --Check if Maximum capacity is not filled.
then
player.Team = randomteam --If it isn't, insert player.
else
if #randomteam:GetPlayers () >= Full.Value --Check the other case.
then
print(randomteam.Name.." is full. Cannot insert "..player.Name.." . Looking for other Teams...")
--Search for Team which isn't full:
repeat
randomteam = Teams[math.random(1,#Teams)]
Full = randomteam:FindFirstChildWhichIsA("IntValue")
until #randomteam:GetPlayers() < Full.Value
player.Team = randomteam --Insert the player.
wait(1) --Debounce to prevent Lag.
end
end
end
--Printing Teams:
print("")
print("Teams:")
print("")
for _,team in pairs(Teams)
do
print(team.Name)
print(table.unpack(team:GetPlayers()))
end
GameStart.Value = true
else --Not enough players.
print("Not enough Players: ("..#game.Players:GetPlayers().."/"..Neededplayers..")")
end
The things inside How do you fix it? Thanks in Advance.

3 comments
It worked for some reason. Thanks!
Sorry to annoy you, but all other Teams than Werewolves and Villagers are nil
Nvm i fixed it