How to detect number of players and then start the round?

I need to watch number of players connected on the server and if required number is hit then start the round.

Here is init.lua

By the way, Idk why props from my cannon don’t remove after time. In singleplayer it worked.

I had to upload it and couldn’t post code here. It was terrible viewed. Maybe because of my UTF-8

I’m not sure on the best way to do it, but you could use a timer and having running everyone 1-2 seconds

timer.Create( “PlayerCountCheck”, 1, 0, function()


Thanks. I was thinking about timers, but wasn’t sure about it.

You’re welcome!
It’s a lot better than Think but I’m not sure if it’s the best solution. Would be good if someone could confirm that Timers are indeed the way to go

It’d probably be better to use a hook, probably PlayerInitialSpawn.

something a little like this
function OnRoundEnd()

function DoPlayerCheck()
local count = #player.GetAll()
if count<MinimumPlayers then
SetRoundState( “waiting” )

hook.Add( “PlayerInitialSpawn”, “PlayerJoin CheckRound”, function( ply ) --Do this in your GM: function instead, if it’s a gamemode
if GetRoundState()==“waiting” then

That way you’re not constantly re-checking when nothing’s changed


Thanks to everyone :slight_smile:

And any ideas about cannon gun? It launches CRT monitors and delete after 5 seconds. But when I tried it in multiplayer, it didn’t remove it.

Hence the comment…

Oh my bad, i thought he meant he needed to check constantly for a round restart, yeah PlayerInitialSpawn is the way to go

Yea I missed the comment. My bad.

Both Prop Hunt and TTT have this sort of thing don’t they? Might be a good idea to take a look at these.

TTT uses timers. This is due to the ability of players to drop in and out of spectator mode, and thus the number of “available” players can change at any given moment.