EN · $ USD
FiveM and Roleplay Servers

FiveM Script Optimization with resmon

7 min read Updated: OyunBulut technical team

In short

resmon is the FiveM client tool that shows how much CPU time (ms) per frame and how much memory each resource uses. Open it by typing resmon 1 in the F8 console. Scripts that stay around 0.00-0.02 ms at idle are healthy; ones that run above 0.1 ms all the time should be investigated. The most common cause of high values is loops running with Wait(0), fixed with a dynamic wait time.

In this guide
  1. How do you open resmon?
  2. How do you read resmon values?
  3. Pinpointing the problem script
  4. The most common cause: Wait(0) loops
  5. Other thread optimizations
  6. Scripts you cannot change: escrow and prebuilt packs
  7. Checking after optimization
  8. Speeding up optimization with AI
  9. Next step: a server you can measure on

resmon (resource monitor) is the built-in FiveM client tool that shows, in milliseconds (ms), how much CPU time each script spends per frame. Open the F8 console in game and type resmon 1 to bring it up. If your players complain about low FPS, the cause is usually not their computers but a few poorly optimized client scripts on your server. This guide shows how to read resmon values, find the problem script and fix the most common coding mistakes.

How do you open resmon?

  1. Connect to the server and open the console with F8.
  2. Type resmon 1 and press Enter. A list of resources appears on screen.
  3. Type resmon 0 to close it.

An important distinction: resmon measures the client side. It shows the FPS impact of client_scripts code running on the player's computer. For server-side delays and hitch warnings in the console, you need FXServer's profiler; we cover that in the Server Thread Hitch Warning guide.

How do you read resmon values?

For each resource in the list, you see:

  • CPU msec: the average CPU time the resource spends each frame. This is the most important column.
  • Time %: how much of the total frame time goes to this resource.
  • Memory: the memory used by the script runtime.
  • Streaming: the size of streamed files the resource loads, such as vehicles, maps and clothing.

Why do milliseconds matter so much? At 60 FPS, a whole frame has about 16.7 ms. The game engine, rendering and every script share that time. If 50 scripts each spend 0.1 ms, the scripts alone take 5 ms, almost a third of the frame.

Which values are good and which are bad?

The ranges below are guideline values widely used by the community:

CPU msecRatingWhat to do
0.00-0.02Ideal (idle)Nothing
0.02-0.10Acceptable (in active use)Review it if it stays at this level at idle too
0.10-0.50InvestigateCheck loops and native calls
0.50 and aboveProblemOptimize or replace it as a priority

It is normal for the value to spike briefly during active use (e.g. with a menu open or near a marker). The real problem is values that stay high while the player is doing nothing.

Pinpointing the problem script

  1. Measure from a fixed spot. Check separately in a busy city center and in an empty area; the number of nearby entities affects the results.
  2. Measure at idle and in action. First watch for 30 seconds without doing anything, then use the feature in question.
  3. Sort the list. Note the top five resources with the highest CPU msec values.
  4. Stop them one by one on a test server. Stop the suspicious resource from the server console with stop and measure the FPS difference. Do not experiment on your live server.
  5. Watch the memory column over several days. A Memory value that keeps climbing points to a leak from tables that are never cleaned up.

The most common cause: Wait(0) loops

In FiveM, client scripts run in loops started with CreateThread. Wait(0) means the loop runs every frame. That is necessary to draw a marker, but calculating distance every frame while the player is miles away from the marker is wasteful.

Bad example:

CreateThread(function()
    while true do
        Wait(0)
        local coords = GetEntityCoords(PlayerPedId())
        local dist = #(coords - vector3(215.0, -810.0, 30.7))
        if dist < 10.0 then
            DrawMarker(1, 215.0, -810.0, 29.7, 0, 0, 0, 0, 0, 0, 1.5, 1.5, 0.5, 0, 150, 255, 120, false, false, 2, false, nil, nil, false)
        end
    end
end)

The version optimized with a dynamic wait time:

local point = vector3(215.0, -810.0, 30.7)

CreateThread(function()
    while true do
        local sleep = 1000 -- check once a second when far away
        local coords = GetEntityCoords(PlayerPedId())
        local dist = #(coords - point)

        if dist < 30.0 then
            sleep = 250 -- getting closer
        end

        if dist < 10.0 then
            sleep = 0 -- every frame only while the marker is visible
            DrawMarker(1, point.x, point.y, point.z - 1.0, 0, 0, 0, 0, 0, 0, 1.5, 1.5, 0.5, 0, 150, 255, 120, false, false, 2, false, nil, nil, false)
            if dist < 1.5 and IsControlJustReleased(0, 38) then -- E key
                TriggerEvent('bizim_script:menuAc')
            end
        end

        Wait(sleep)
    end
end)

This simple change brings the script's load down to practically zero while the player is away from the area.

Other thread optimizations

Use the vector operator for distance checks

GetDistanceBetweenCoords is a native call and costs more than the #(a - b) vector operation. Always prefer the vector operator in new code.

Cache values that do not change

Instead of calling natives like PlayerPedId() dozens of times per frame, store the result in a variable. If you use ox_lib, the cache.ped and cache.vehicle values do this for you.

Events and zone systems instead of loops

Instead of opening a separate loop for every interaction point, check all points in a single loop, or use ox_lib's lib.points and lib.zones tools and targeting systems like ox_target. Instead of constantly checking for state changes (polling), react with events and state bag change handlers.

Limit drawing and text natives

DrawMarker, helper functions like DrawText3D, and HUDs that constantly print text to the screen have to run every frame, which is why they are usually the code that burns the most ms. Do not draw points at distances the player cannot see, limit how many markers can be on screen at once, and where possible update static HUD info on the NUI side, only when the value changes.

Send fewer events to the server

Sending TriggerServerEvent from the client every frame or very frequently raises both client and server load. The server already knows data like position through OneSync; send an event only when a real action happens.

Keep NUI lightweight

Sending data to HTML interfaces with SendNUIMessage every frame, and CSS animations that keep running in hidden interfaces, lower FPS. Send data only when it changes, and truly hide closed interfaces.

Scripts you cannot change: escrow and prebuilt packs

You cannot open and edit the code of scripts encrypted with Cfx.re Asset Escrow. If such a script keeps showing high values in resmon, your options are limited:

  • Review the config file. Escrow scripts usually leave the config file open; settings like update frequency, draw distance or interaction method can reduce the load.
  • Contact the developer with your measurements. A resmon screenshot and details on when the load rises make it easier for the developer to reproduce the problem.
  • Consider an alternative. If another script does the same job more efficiently, switching can be the cleanest long-term fix.

With prebuilt server packs, the problem is usually not one script but dozens of unused scripts running together. First remove the ensure lines for resources you do not use, then measure the rest with resmon.

Checking after optimization

  1. Note the resmon values before the change.
  2. Update the script on a test server and measure from the same spot for the same amount of time.
  3. Check that the feature still works correctly; if the wait time gets too long, key presses feel delayed.
  4. After moving it to the live server, ask a few players for FPS feedback.

Speeding up optimization with AI

Going through the loops of dozens of scripts one by one takes time. Giving the problem file to an AI assistant with a clear instruction like "convert the Wait(0) loops to dynamic wait times" and having it rewrite the code shortens the process. The AI Developer Pro plan, which you can use for FiveM scripts, includes 1M tokens; that is a solid start for reviewing the heaviest scripts of a mid-sized server. We explain how to give the right instructions in the guide to writing FiveM scripts with AI. Either way, compare before and after values with resmon after every change; do not trust an optimization you have not measured.

Next step: a server you can measure on

The safe way to optimize is to run a copy of your live server in a test environment. The OB-FIVEM-4 FiveM server, with 4 CPUs and 8 GB DDR5 RAM, is a good fit for testing a full ESX or QBCore setup or running a live server of up to 64 slots. For other options, see the OyunBulut FiveM server plans, and for script development help, see FiveM packages and services. First find your five heaviest scripts with resmon, then fix them with the patterns in this guide; your players will feel the difference the very first evening.

Frequently asked questions

How do you open resmon in FiveM?

In game, open the console with F8 and type resmon 1. Use the resmon 0 command to close it.

How many ms is normal in resmon?

As a guideline, 0.00-0.02 ms is ideal for an idle script. Scripts that run above 0.1 ms all the time should be investigated, and 0.5 ms or more should be optimized as a priority.

Does resmon show server performance too?

No. resmon only shows client-side script load and relates to player FPS. For server-side delays, you need FXServer's profiler.

Is using Wait(0) always wrong?

No. It is needed for work that must happen every frame, such as drawing markers or checking key presses. The problem is when the loop keeps running every frame while the player is far from the relevant area.

The Memory value keeps rising. What does it mean?

The script may not be cleaning up the tables or data it uses; this is a memory leak. Over time it lowers client performance, and the script's code needs to be fixed.

For this guide

Recommended plans

The OB-FIVEM-4 plan gives you a full FiveM test or live environment where you can safely try optimizations, while the AI Developer Pro plan speeds up rewriting the loops of heavy scripts.

OB-FIVEM-4

Recommended

8 GB DDR5 RAM

$21.62/mo

+VAT

  • Processor4 CPU
  • Disk70 GB NVMe
  • LocationIstanbul
  • DDoS
  • Automatic Setup

1M tokens / month — usage percentage and stats tracking.

$9.83/mo

+VAT

  • LocationIstanbul
  • 1M tokens
  • % + stats
  • Automatic Setup

FiveM — tüm paketler FiveM Services — tüm paketler

Need help with setup?

Send questions about your service in a support ticket, and our technical team will walk you through it step by step.