Stellar AI

Blog

QBCore Script Performance Optimisation

Updated 27 September 2026

Measure before rewriting

Do not optimise a QBCore resource only because it looks large. First identify what actually runs frequently: loops, event handlers, zone checks, UI updates or database queries.

A small function running every frame can cost more than a large function triggered once during a job action.

Avoid zero-wait loops unless they are truly needed

Client loops that run every frame should be rare. Increase waits when the player is far from an interaction, or use zones and event-driven state changes instead of constantly polling.

Adaptive sleeps are often a simple improvement: check less frequently while idle and temporarily increase frequency when the player is near an active interaction.

Keep events narrow and validated

Do not broadcast large payloads to every player when only one client needs the update. Send the smallest useful data to the smallest relevant audience.

Server events should also validate the action rather than trusting a client to report the final reward or state. Performance and security often improve together when authority is centralized.

Reduce repeated database work

Cache slow-changing configuration where appropriate and avoid querying the same information several times during one action. Batch related writes when your framework and database layer support it safely.

Do not cache security-sensitive or rapidly changing player state without a clear invalidation strategy.

Optimise the workflow, not just milliseconds

Readable files, predictable exports and clear ownership reduce debugging time. A resource that is slightly faster but impossible to maintain can still cost more overall.

Use profiling results, make one change, retest and keep the change only if the improvement is measurable.

Check the resource after realistic player activity

Measure again with several players using the resource at the same time, not only while standing alone on a development server. Watch client frame time, server hitch warnings and database latency while players enter zones, open menus and trigger job actions. A useful optimisation should reduce repeated work without changing permissions, rewards or expected gameplay behaviour.

Test before production.

AI-generated code should be reviewed in a private Roblox Studio test place or FiveM development server before release. Keep versioned backups and verify permissions, inputs and data writes.

Related guides

Want it fixed for you? The £99 Priority Script Fix is a one-off fix for a FiveM or Roblox script. Memberships start at £8 a month on the plans page.

Related tools: QBCore script generator · Fix a FiveM Lua error · all script generators