So basically I have a teams script and I need it to count how many players there are in a game, so it can determine the amount of teams. Here is my script:
''''
repeat wait() until #game.Players:GetPlayers()>= --idk
print("1")
local Teams = game:GetService("Teams")
local PlayerList = game.Players:GetPlayers()
local TeamColors = {
BrickColor.Red(),
BrickColor.Blue(),
BrickColor.Green(),
BrickColor.White(),
BrickColor.Black()
} --add based on the max num of teams in your game
print("2")
local TeamColorCount = 1
for Counter = 1, #PlayerList, 2 do
local Team = Instance.new("Team")
print("3")
local Player1, Player2 = PlayerList[Counter], PlayerList[Counter+1]
print("4")
-- creating the team
Team.TeamColor = TeamColors[TeamColorCount]
print("5")
Team.Parent = Teams
print("6")
-- adding players to team
Player1.Team = Team
print("7")
--checking that there is a second player on the team to add
if Player2 then
print("8")
Player2.Team = Team
print("9")
end
TeamColorCount = TeamColorCount + 1
print("10")
end
'''
You Could set a variable to it and Update it at the end of something like a Countdown
Use what Xueify Posted and use if then on the Countdown to when its 0 and update the var , sorry for my bad explanation.
You can do this to get the amount of players currently on the server.
-- get the players service
local players = game:GetService("Players")
-- # gets the amount of stuff in a table but it could also work with GetChildren() and GetPlayers()
local count = #players:GetPlayers()
Sorry for bad explaining before, but I’m trying to make it so that the the teams script work on any amount of player, because right now it doesn’t… @Xueify@Hurriedcarrot62@j8cksxn@MrNicNac
Which is at the beginning, and it doesn’t work, and no errors, but it doesn’t print.
''''
local amtofplr = 0
for i, v in pairs(game.Players:GetPlayers()) do
amtofplr = amtofplr + 1
print("Player")
end
print("1")
local Teams = game:GetService("Teams")
local PlayerList = game.Players:GetPlayers()
local TeamColors = {
BrickColor.Red(),
BrickColor.Blue(),
BrickColor.Green(),
BrickColor.White(),
BrickColor.Black()
} --add based on the max num of teams in your game
print("2")
local TeamColorCount = 1
for Counter = 1, #PlayerList, 2 do
local Team = Instance.new("Team")
print("3")
local Player1, Player2 = PlayerList[Counter], PlayerList[Counter+1]
print("4")
-- creating the team
Team.TeamColor = TeamColors[TeamColorCount]
print("5")
Team.Parent = Teams
print("6")
-- adding players to team
Player1.Team = Team
print("7")
--checking that there is a second player on the team to add
if Player2 then
print("8")
Player2.Team = Team
print("9")
end
TeamColorCount = TeamColorCount + 1
print("10")
end
'''