Disable or reduce NPC traffic and peds in FiveM: density natives
Turn off or reduce NPCs, traffic and parked cars in FiveM with the density multiplier natives, the per-frame rule, routing buckets, removing cops and the cost of each option.
Typical symptoms:
Streets full of NPCs and traffic, low fps in the city, or random police responses nobody asked for.Population in GTA is controlled by a set of natives that you call on the client. The main trap is that most of them reset every frame. This article shows the natives, the loop they need, the server side option, and the trade-offs of an empty city.
The one rule: every frame
The density multipliers apply to the current frame only. Call them once at startup and they do nothing a moment later. They must run in a loop with no delay:
CreateThread(function()
while true do
SetVehicleDensityMultiplierThisFrame(0.0)
SetPedDensityMultiplierThisFrame(0.0)
SetRandomVehicleDensityMultiplierThisFrame(0.0)
SetParkedVehicleDensityMultiplierThisFrame(0.0)
SetScenarioPedDensityMultiplierThisFrame(0.0, 0.0)
Wait(0)
end
end)A multiplier is between 0.0 (none) and 1.0 (the default amount). Each native controls a different part:
| Native | Controls |
|---|---|
SetVehicleDensityMultiplierThisFrame |
Moving traffic |
SetRandomVehicleDensityMultiplierThisFrame |
Random vehicles on the roads |
SetParkedVehicleDensityMultiplierThisFrame |
Cars parked on the street |
SetPedDensityMultiplierThisFrame |
Walking pedestrians |
SetScenarioPedDensityMultiplierThisFrame |
Peds doing activities (interior, exterior) |
SetScenarioPedDensityMultiplierThisFrame takes two values, one for the interior and one for the exterior.
Reduce instead of removing
A city with no one in it looks broken, and players notice. Use a value between 0 and 1 to thin it out:
local traffic = 0.3
local peds = 0.4
CreateThread(function()
while true do
SetVehicleDensityMultiplierThisFrame(traffic)
SetRandomVehicleDensityMultiplierThisFrame(traffic)
SetParkedVehicleDensityMultiplierThisFrame(traffic)
SetPedDensityMultiplierThisFrame(peds)
SetScenarioPedDensityMultiplierThisFrame(peds, peds)
Wait(0)
end
end)Try 0.3 to 0.5 first, then adjust to your server. Put the values in a config file so you can change them without touching the code.
Server side: routing buckets
The server can switch the population off for a whole routing bucket, which is useful for an instance like an interior or an event, without a client loop:
-- server
SetRoutingBucketPopulationEnabled(bucketId, false)With this, no ambient NPCs or traffic spawn for the players in that bucket. Bucket 0 is the default world. Leave it on for the main world and disable it for private instances. See routing buckets for how to put players in one.
Remove the cops and the dispatch
Setting the density to zero does not stop the police response. Wanted levels and dispatch run on their own systems. To remove them, turn them off one by one:
CreateThread(function()
SetMaxWantedLevel(0)
SetCreateRandomCops(false)
SetCreateRandomCopsNotOnScenarios(false)
SetCreateRandomCopsOnScenarios(false)
for service = 1, 15 do
EnableDispatchService(service, false)
end
end)
CreateThread(function()
while true do
if GetPlayerWantedLevel(PlayerId()) > 0 then
SetPlayerWantedLevel(PlayerId(), 0, false)
SetPlayerWantedLevelNow(PlayerId(), false)
end
Wait(500)
end
end)EnableDispatchService takes a service index and a boolean. The loop over 1 to 15 covers the police, helicopter, fire, ambulance and other services the game defines. The wanted level loop catches anything that slips through.
If you keep the police on your server for roleplay, do not disable the services for players who are on duty. Handle that case in your job script.
Other things you might want off
Population is more than peds and cars. These natives remove a few other sources, each takes a boolean:
SetGarbageTrucks(false)
SetRandomBoats(false)
SetRandomTrains(false)Call them once at startup, they do not need a per frame loop.
Performance trade-offs
What you gain. Every ped and vehicle is simulated, drawn and synced. Cutting them cuts the client's cost and the number of entities in the network. On weak PCs this can be a large fps difference. For other fps fixes, see low FPS in FiveM.
What you pay. A loop with Wait(0) runs every frame, so keep it tiny and put the natives in one single thread. A loop of five calls is cheap, but ten different scripts each with their own loop is not. Check that your server does not already set the density, and your resource monitor in resmon.
The atmosphere. A world with no NPCs is lifeless. Reducing traffic and keeping some peds is a better middle ground, and parked cars are cheap to keep since they do not move.
Gameplay. Many scripts rely on peds or cars: a drug sale, a robbery with hostages, a heist with traffic. Test them with your density settings, since a job that needs a passer-by will fail in an empty city.
Common mistakes
- Calling the multipliers once. They reset every frame, use a loop.
- A long
Waitin the loop. WithWait(1000)the density applies one frame per second and the NPCs spawn in the gaps. It must beWait(0). - Two scripts with different values. The last call of the frame wins, so you get inconsistent results. Keep one source.
- Forgetting the parked cars. Traffic at zero and parked cars at the default still leaves a street full of cars.
- Expecting the server to remove NPCs it does not own. Ambient population is client side, apart from the routing bucket switch.
Checklist
| Symptom | Fix |
|---|---|
| NPCs return after a moment | Call the density natives every frame with Wait(0) |
| Traffic gone, parked cars stay | Add SetParkedVehicleDensityMultiplierThisFrame |
| Peds sit in scenarios | Add SetScenarioPedDensityMultiplierThisFrame(interior, exterior) |
| Cops still show up | Wanted level 0, EnableDispatchService off, random cops off |
| Need no NPCs in an instance | SetRoutingBucketPopulationEnabled on the server |
| City feels empty | Use values like 0.3 to 0.5 instead of 0.0 |
| High resmon time | One loop only, no duplicate scripts |
Quick answers
Why do NPCs come back after I set the density to 0?
The density natives only last for one frame. If you call them once, the game goes back to the default on the next frame, so they must be called in a loop that runs every frame.
Does disabling NPCs improve performance?
Yes, fewer peds and cars means less work for the client, and more fps on weak machines. It also makes the city feel empty, so many servers reduce the density instead of removing it.
How do I remove the police response?
Turn off the dispatch services with EnableDispatchService, set the wanted level to 0 and stop random cops. Do all three, since each covers a different part.
Scripts that skip this problem
Advanced BoostingTablet-driven vehicle boosting: contracts from class D to S+, crews and a live queue.View script →
Quest CreatorA visual editor for quests and NPC dialogues, built node by node in game.View script →
CCTV Security CamerasPlaceable cameras, a live multi-view tablet and printed evidence photos.View script →