Page 1 of 1

How to count players with a particular tag

Posted: Fri Mar 23, 2018 5:06 pm
by WIZ4
This command print that tag = nil

Code: Select all

/c game.print(#game.players.tag['[Tag]'])
Screenshot_7.png
Screenshot_7.png (114.92 KiB) Viewed 1674 times

Re: How to count players with a particular tag

Posted: Fri Mar 23, 2018 5:24 pm
by posila
game.players is array of players, it doesn't contain "tag" unless there is a player named "tag".

Re: How to count players with a particular tag

Posted: Fri Mar 23, 2018 5:50 pm
by WIZ4
Oh, okay

Re: How to count players with a particular tag

Posted: Fri Mar 23, 2018 6:37 pm
by eradicator

Code: Select all

local count = 0
for _,player in pair(game.players) do
  if player.tag == 'whatever' then
    count = count +1
    end
  end
game.print(count)
(untested)

Re: How to count players with a particular tag

Posted: Fri Mar 23, 2018 6:57 pm
by WIZ4
eradicator wrote:

Code: Select all

local count = 0
for _,player in pair(game.players) do
  if player.tag == 'whatever' then
    count = count +1
    end
  end
game.print(count)
(untested)
Yes it works fine, thanks!