Stop/Start resource when x players are online

Hi. I’m thinking about a whitelist system that launches when there’s, let’s say, 15 players online.
I’ve tried using NetworkGetNumConnectedPlayers(), then if onlinePlayers > 15 run ExecuteCommand(“start whitelist”), but got no luck. Do you guys have an idea on how to do that?

Put this in a server script

AddEventHandler('playerConnecting', function(PlayerName, KickReason, Deferrals)
	if GetNumPlayerIndices() > 15 then
		StartResource('Whatever')
	end
end)

AddEventHandler('playerDropped', function(DropReason)
	if GetNumPlayerIndices() <= 15 then
		StopResource('Whatever')
	end
end)
1 Like

instead of starting resources on certain events you should always leave the resource running and do something when there are more than x players.

eg: on player connect, count online players
if online players more X, check whitelist.

i bet starting and stopping resources is more intense as just having it run and listen to an event

2 Likes

There are natives for starting and stopping resources, no need for ExecuteCommand. And like Slluxx said, its not good to stop and start resources. Just run what ever needs ran when there are enough players.

1 Like

@Flatracer That resolved my problem thanks!

Although i’ve decided to go with @Slluxx and @Nick78111 ideas.

Thank you all!