How to Reduce NPC Density in FiveM: Complete Guide
Learn how to optimize your FiveM server performance by reducing or completely disabling NPC and traffic density using native Lua scripting.

Grand Theft Auto V was designed as a single-player game populated by thousands of AI-controlled pedestrians and vehicles. While this creates a vibrant, living world in story mode, it can cause severe performance and synchronization issues in a multiplayer FiveM environment.
Whether you are running a 100+ player roleplay server or a high-speed racing server, learning how to reduce or completely eliminate NPC density is a crucial step in optimizing your FiveM server performance.
Why Should You Reduce NPC Density?
Before diving into the code, you should understand why almost every major server alters the default AI density.
Server and Client Performance
Every NPC (Non-Player Character) requires CPU power to calculate pathfinding, AI behavior, and physics. When you multiply this by 50+ players scattered across Los Santos, the server and the players' clients struggle to keep up. Reducing NPC density is one of the fastest ways to boost FPS in FiveM.
Desync and "Ghost Cars"
If you have ever driven down the highway at 150mph and crashed into an invisible car, you have experienced desync. High NPC vehicle density overwhelms the network state, meaning player A sees a car that player B does not. Less AI means less data to synchronize.
Roleplay Immersion
In serious RP environments powered by FiveM Frameworks, players are relied upon to populate the world. Having random AI walk into active hostage negotiations or AI cars ramming into pulled-over vehicles breaks immersion instantly.
The Solution: Lua Native Functions
To control NPC density, we use specific native functions provided by Cfx.re. Because these functions must run every single game frame to override the base game's engine, they are placed inside a client-side Citizen.CreateThread loop.
The Core Density Functions
There are five primary natives you need to know:
SetVehicleDensityMultiplierThisFrame(multiplier)- Controls moving traffic.SetPedDensityMultiplierThisFrame(multiplier)- Controls walking pedestrians.SetRandomVehicleDensityMultiplierThisFrame(multiplier)- Controls parked/random cars.SetParkedVehicleDensityMultiplierThisFrame(multiplier)- Controls static parked cars in lots.SetScenarioPedDensityMultiplierThisFrame(multiplier, multiplier)- Controls NPCs doing activities (smoking, drinking coffee, sitting).
The multiplier is a float value between 0.0 (completely disabled) and 1.0 (default GTA V density).
How to Create the Density Control Script
We will create a lightweight, standalone resource to handle this so it does not interfere with your other scripts.
Step 1: Create the Folder Structure
- Navigate to your server's
resourcesfolder. - Create a new folder named
traffic_control. - Inside
traffic_control, create two files:fxmanifest.luaandclient.lua.
Step 2: Configure the fxmanifest.lua
Open fxmanifest.lua and define the resource. This tells FiveM to load your client script.
fx_version 'cerulean'
game 'gta5'
author 'VertexMods'
description 'Controls NPC and Traffic Density'
version '1.0.0'
client_script 'client.lua'
Step 3: Write the Client Script (client.lua)
Open client.lua and insert the following code. This example reduces all traffic and pedestrians to 20% of their normal volume, which is the "sweet spot" for active RP servers.
-- Set the desired density multiplier (0.0 to 1.0)
local densityMultiplier = 0.2
Citizen.CreateThread(function()
while true do
Citizen.Wait(0) -- Must run every frame
-- Apply the multipliers
SetVehicleDensityMultiplierThisFrame(densityMultiplier)
SetPedDensityMultiplierThisFrame(densityMultiplier)
SetRandomVehicleDensityMultiplierThisFrame(densityMultiplier)
SetParkedVehicleDensityMultiplierThisFrame(densityMultiplier)
SetScenarioPedDensityMultiplierThisFrame(densityMultiplier, densityMultiplier)
-- Optional: Disable AI emergency services
-- This prevents AI cops/medics from responding to player crimes
local playerPed = GetPlayerPed(-1)
local pos = GetEntityCoords(playerPed)
ClearAreaOfCops(pos.x, pos.y, pos.z, 400.0)
end
end)
Complete Eradication (Zero NPCs)
If you are running a drift server or a pure PvP arena, you likely want zero AI. Simply change local densityMultiplier = 0.2 to 0.0.
You may also want to add garbage cleanup to remove broken AI vehicles:
-- Add inside the while loop if multiplier is 0.0
SetGarbageTrucks(false)
SetRandomBoats(false)
Advanced Tip: Dynamic Density
Running a zero-wait thread (Citizen.Wait(0)) is standard for these frame-based natives, but if you want to optimize even further, you can adjust the density based on the current player count.
Many advanced servers use server-side callbacks to check how many players are online:
- 0β30 Players:
0.8Density (Make the city feel alive when it's quiet). - 30β80 Players:
0.4Density (Balance performance). - 80+ Players:
0.0Density (Players populate the city entirely, max performance).
Integration with Other Resources
Ensure that your new traffic_control script is added to your server.cfg:
ensure traffic_control
If you are using robust frameworks like QBCore or ESX, ensure this script starts after the framework to prevent base resources from overriding your native calls.
Conclusion
Reducing NPC density is the simplest, most effective modification you can make to improve server stability and hit registration. Whether dialing it down for performance or turning it off completely for competitive gameplay, a few lines of Lua code will drastically improve the player experience.
Looking to optimize further? Check out our guides on migrating data properly from MySQL Async to OxMySQL or explore high-performance FiveM Scripts built with optimization in mind.


