Get number of players

Hey, i need help with getting the number of players for my multiplayer lobby.
I red on the internet that i should use the Player Array in the game state, so i tried this:

And then casted from the HUD to the game state to get the variable, that resulted like this:

Player one gets the number one, player two gets the number 2 and so on…

Then i red that i can use the Get Num Players from the game Mode so i tried that like this:

That gave me a weird result:

This time both players got nothing, not a “0” nothing, the HUD text disapeares?

Where/How should i get the number of players currently connected?

Sorry for bad English!
Thanks in advance! :smiley:

You setting Total Players only once, when GameMode object is created and “BeginPlay” is called, at that point there no any PlayerController is initated so it will return 0 and because you do it only once at begining it will stay at 0 forever.

Why not just use “Get Num Players” directly?

You can use “Get Number Players”, but then you can’t just give every Player the same number, like said.
But you can use a For Loop from 0 to “Get Number Players” and assign in every Loop another Player.

Be advised that Game Mode exists only on Server. If you call “Get Game Mode” on Client side, you will receive “None”.