How do you get the player-count of a running server?

So, I’m trying to make a system for where if a player isn’t allowed (by UserId)into the game, they are automatically kicked back out. The problem is, I don’t know how to get the value of how mayne plaers are in the server. Does anyone know?

game.Players.PlayerAdded:Connect(function(player)
	local bannedUsers = {}
	local playerUserId = "Player"..player.UserId
	for game:Players, Player in pairs(game.Players:GetPlayers()) do	
		wait(0.2)
		if playerUserId then playerUserId = bannedUsers[] do
				player:Kick("You are banned from this game")
			end
		end
	end
end)
1 Like

to find the number of players in a server use

#game.Players:GetPlayers()

or maybe assign this to a variable

PlayerCount = #game.Players:GetPlayers()
print(PlayerCount) -- will print a number value which will be the number of players
2 Likes

alr I’ll be inactive for a while
but thanks for the tip, I’ll try it

2 Likes

In server script service to get it you just need local Players = 0
Game.Players.PlayerAdded:Connect()
Players += 1
print(Players)
end)

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.