✓ Accepted answer
Use the octothorpe (#):
print(#game.Players:GetPlayers())
The octothorpe is Lua's "counting" operator, which returns the number of players in the Players folder via the GetPlayers() method. If you are the only one in your game (i.e. in Studio) you would get this output:
>> 1
Octothorpes, especially for counting the number of players in a game, are extremely useful for PvP games. Most PvP games require 2 players in order to play them, so you can use the octothorpe to get the number of players.
Because the value returned is a number, you can do this:
local players = game.Players:GetPlayers()
if #players < 2 then return end
if #players >= 2 then
end
Just something to think about while we are on this topic. If you have any questions, please ask them.
Thanks, MCAndRobloxUnited
2 comments
GetPlayers() returns a list, so you can define a variable like "#players" to it to get the number of indices
print(#game.Players:GetPlayers())