I want this script to determine how many players are in my game. I want it to update a value, and then I want that value to print so I know the script is working. Output didn't give me anything.
Can someone please help? Here's the script:
local player_count = 0 while wait() do local Players = {} for _,v in pairs(game.Players:GetPlayers()) do table.insert(Players,v) player_count = player_count + 1 end end print(player_count)
There is something called NumPlayers.
print(game.Players.NumPlayer) --That's it. game.Players.NumPlayer.
There is another method that is not as effective.
print(#game.Players:GetChildren()) --# returns the number of things in a table, in this case: the number of children in players.
Hope it helps! (There really is no scripting needed.)
How to see how many players are on a team
local team1 = 0 local team2 = 0 local otherteam = 0 local team1color = BrickColor.new("Bright red") local team2color = BrickColor.new("Bright blue") --Maybe a loop? for _,player in pairs(game.Players:GetChildren()) do if player.ClassName == "Player" then if player.TeamColor = team1color then team1 = team1+1 elseif player.TeamColor = team2color then team2 = team2+1 else otherteam = otherteam+1 end end end print("There are "..team1.." players in the red team and "..team2.." players in blue and there are "..otherteam.." left.")