I've encounter a problem where this simple player counter prints 0 instead of 1 when there is one person that is currently in the game.
local players = game.Players local playercount = #(players:GetPlayers()) print (playercount)
Am I doing something wrong in this script?
Any help is greatly appreciated
You should make a function for this so it's much clean if you know what I mean.
function get_players() local count = 0 for _, a in pairs(game:service'Players':players()) do --// gets all the players count = count + 1 --// adds 1 to the count if a player was found end return count --// returns the number of players end
You can then do
local amount_of_players = get_players() --// now amount_of_players will be the amount of players in your server print(amount_of_players)