PiTyUs.Hire me

Frameworks

Creating zones in FiveM with ox_lib (and PolyZone)

Detect when players enter areas in FiveM: ox_lib zones (box, sphere, poly) with onEnter, onExit and inside, the /zone creator command, PolyZone for older resources, performance tips, server-side checks, and choosing between zones, points and targets.

Updated 10 min readBy PiTyUs · FiveM developer

Overview

Garages, safe zones, drug fields, job areas and speed limits all ask the same question: is the player inside this area right now? Zone libraries answer it efficiently and give you enter and exit events, so your script reacts once instead of measuring distances every frame.

The three zone shapes

ShapeDefined byGood for
Spherecoords, radiusPoints of interest, round areas
Boxcoords, size, rotationRooms, parking bays, buildings
Polypoints (vec3 list), thicknessIrregular areas — fields, beaches, districts

ox_lib zones in code

client.lualua
local safe = lib.zones.poly({
    points = {
        vec3(-1040.0, -2750.0, 20.0),
        vec3(-1000.0, -2710.0, 20.0),
        vec3(-960.0, -2750.0, 20.0),
        vec3(-1000.0, -2790.0, 20.0),
    },
    thickness = 12.0,
    debug = false,
    onEnter = function()
        lib.notify({ title = 'Safe zone', description = 'Weapons disabled', type = 'inform' })
    end,
    onExit = function()
        lib.notify({ title = 'Safe zone', description = 'You left the safe zone', type = 'warning' })
    end,
    inside = function()
        DisablePlayerFiring(cache.playerId, true)
    end,
})

local pump = lib.zones.sphere({ coords = vec3(265.0, -1261.0, 29.3), radius = 6.0, onEnter = function() lib.showTextUI('[E] Refuel') end, onExit = function() lib.hideTextUI() end })

-- later: safe:remove()

onEnter and onExit fire once; inside runs every frame while the player is in the zone, which is what DisablePlayerFiring needs. Set debug = true to see the shape while developing.

Drawing zones in game

  1. Give yourself the ACE: add_ace group.admin command.zone allow.
  2. Type /zone poly (or box, sphere) and follow the on-screen controls to place points.
  3. Name and save the zone; ox_lib appends ready-to-paste code to ox_lib/created_zones.lua.

PolyZone (older resources)

client.lua — PolyZone syntaxlua
local zone = BoxZone:Create(vector3(441.0, -982.0, 30.7), 10.0, 8.0, {
    name = 'mrpd_lobby',
    heading = 0,
    minZ = 29.0,
    maxZ = 33.0,
    debugPoly = false,
})

zone:onPlayerInOut(function(isInside)
    print(isInside and 'entered' or 'left')
end)

PolyZone (with BoxZone, CircleZone, PolyZone:Create and ComboZone) is still a dependency of many QBCore resources, but it is no longer actively developed. New code should use ox_lib zones; there is no need to rewrite working resources just to switch.

Zones, points or targets?

NeedUse
React when entering an areaZone
Show “[E] Open” near one spotlib.points or a small sphere zone
Click on a specific object, NPC or doorox_target — see ox_target guide

Server-side confirmation

Zones live on the client. When entering a zone unlocks something valuable — selling drugs, a job payout — check the player’s coordinates on the server too: #(GetEntityCoords(GetPlayerPed(src)) - zoneCenter) < radius. See secure server events.

Frequently asked questions

How do I create a zone in FiveM?

With ox_lib: lib.zones.box, lib.zones.sphere or lib.zones.poly with onEnter/onExit handlers.

Is PolyZone still used?

Yes, by many older and QBCore resources, but it is no longer actively developed. ox_lib zones are the modern replacement.

How do I draw a polygon zone in game?

Use ox_lib’s restricted /zone poly command; saved zones are written to created_zones.lua in ox_lib.

Do zones cost performance?

Very little, as long as inside handlers stay light.

Need this built, not just explained?

Ten years of FiveM work, from Lua to NUI

Custom resources, React NUI, ESX / QBCore / Qbox integration, OneSync performance audits and security reviews — plus the websites and SEO around your server brand.

Related guides