Halloween Edition36 maps, limited runlimited runShop the drop
Performanceintermediate9 min readupdated 11 Sept 2026

Entity limits and cleanup on a FiveM server

The short answer

Count entities on the server with GetAllVehicles(), GetAllPeds() and GetAllObjects(), watch how the numbers grow between restarts, and find the resources that create entities without deleting them. Fix the scripts (delete on job end, on resource stop, on player drop), add a conservative cleanup for abandoned vehicles with a warning, and lower population density if AI traffic is the load.

Every networked vehicle, ped and object has to be synced to nearby players. Scripts that spawn things and never delete them — job vehicles, dropped props, test spawns — slowly fill the world until sync slows down and odd bugs appear. Counting and cleaning entities is basic server hygiene.

Entity limits and cleanup on a FiveM server — illustrated with a FiveM-compatible minimap render

#Counting entities

server.lua — /entities command for staff
RegisterCommand('entities', function(src)
    local msg = ('vehicles %d · peds %d · objects %d'):format(#GetAllVehicles(), #GetAllPeds(), #GetAllObjects())
    if src == 0 then print(msg) else TriggerClientEvent('chat:addMessage', src, { args = { 'Entities', msg } }) end
end, true)

Run it after a restart and again a few hours later. Healthy servers level off; leaking ones keep climbing.

#Finding the leak

  • Group vehicles by model and plate pattern — job vehicles often share a prefix.
  • Check entity state bags or owners to see which script created them.
  • Stop suspect resources one by one on a test server and watch the counts.

#Cleaning up safely

server.lua — remove empty, unowned vehicles
local function cleanup()
    TriggerClientEvent('chat:addMessage', -1, { args = { 'Server', 'Empty vehicles are cleared in 60 seconds.' } })
    Wait(60000)
    for _, veh in ipairs(GetAllVehicles()) do
        local occupied = false
        for seat = -1, 6 do
            if GetPedInVehicleSeat(veh, seat) ~= 0 then occupied = true break end
        end
        if not occupied and not Entity(veh).state.owned then
            DeleteEntity(veh)
        end
    end
end

Mark player-owned vehicles (for example with an owned state bag set by your garage) so cleanup never deletes them. Server-side spawning and orphan mode: server-side entities.

#AI population

Traffic and pedestrians are entities too. Lower densities in busy servers, or disable AI population entirely with onesync_population false if your game mode does not need it — see traffic and ped density.

Share this guideXRedditFacebook

Questions

How do I count entities on my FiveM server?
On the server, #GetAllVehicles(), #GetAllPeds() and #GetAllObjects().
Why do entity counts keep growing?
A script spawns entities without deleting them. Find it by watching counts while stopping resources.
Should I auto-delete vehicles?
Only empty, unowned ones, with a warning beforehand.
How do I turn off AI traffic?
Lower densities with scripts or set onesync_population false to disable population.

Ready to pick a map?

Twelve themes on three base map styles, $8 each, instant download.

Relevant to what you just read

Look it up while you work

The reference tables this guide leans on, free and without an account.