Santa & Christmas Edition36 maps, limited runlimited runShop the drop
Scriptingintermediate10 min readupdated 11 Sept 2026by · how we test

Scripting a shooting range for FiveM

The short answer

Spawn target props locally when the player starts a round, check each frame (only during the round) whether a target was hit with HasEntityBeenDamagedByEntity(target, ped, true), count and reset it with ClearEntityLastDamageEntity, stop after a timer, and send the final score to the server, which validates it (player in the range zone, plausible numbers) before granting anything like licence progress.

A shooting range gives new players something to do with their first pistol, gives police a qualification test and gives gun stores a reason to exist. The core is small: spawn some targets, count hits for a limited time, show a score. Everything else is presentation.

Scripting a shooting range for FiveM — illustrated with a FiveM-compatible minimap render

#A round in code

client.lua
local TARGET = `prop_mytarget` -- a target model you stream or pick in CodeWalker
local SPOTS = { vec3(13.0, -1098.0, 29.8), vec3(15.5, -1097.2, 29.8), vec3(18.0, -1096.4, 29.8) }

local function round(seconds)
    RequestModel(TARGET)
    while not HasModelLoaded(TARGET) do Wait(0) end
    local targets = {}
    for i, p in ipairs(SPOTS) do
        targets[i] = CreateObject(TARGET, p.x, p.y, p.z, false, false, false)
        FreezeEntityPosition(targets[i], true)
    end

    local ped, hits = PlayerPedId(), 0
    local ends = GetGameTimer() + seconds * 1000
    while GetGameTimer() < ends do
        for _, t in ipairs(targets) do
            if HasEntityBeenDamagedByEntity(t, ped, true) then
                hits = hits + 1
                ClearEntityLastDamageEntity(t)
            end
        end
        Wait(0)
    end

    for _, t in ipairs(targets) do DeleteEntity(t) end
    SetModelAsNoLongerNeeded(TARGET)
    TriggerServerEvent('range:finished', hits, seconds)
end

Pick a target model that exists in your game build or stream your own; check the name in CodeWalker before using it.

#Validating on the server

server.lua
local RANGE = vec3(15.0, -1100.0, 29.8)
local MAX_HITS_PER_SECOND = 4

RegisterNetEvent('range:finished', function(hits, seconds)
    local src = source
    if type(hits) ~= 'number' or type(seconds) ~= 'number' then return end
    if #(GetEntityCoords(GetPlayerPed(src)) - RANGE) > 25.0 then return end
    if hits < 0 or hits > seconds * MAX_HITS_PER_SECOND then return end
    -- record practice or licence progress here
end)

The client decides the score, so treat it as a claim: check location and plausibility, rate-limit the event, and never pay large rewards from it. Licences: weapon licence system.

#Making it feel good

  • A countdown and a result screen (NUI or ox_lib notify).
  • Moving targets by setting coordinates each frame within a small range.
  • Loaner weapons that are removed after the round.
  • Leaderboards stored on the server per weapon class.
Share this guideXRedditFacebook

Questions

How do I detect when a target is shot in FiveM?
Check HasEntityBeenDamagedByEntity(target, playerPed, true) during the round and reset it with ClearEntityLastDamageEntity.
Should targets be networked?
For a solo range, local props are simpler and cheaper.
Can players cheat the score?
The client reports it, so validate on the server and keep rewards small.
Can the range grant a weapon licence?
Yes — record passed tests on the server and let your licence system use that record.

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.

  • All 21,631 object model namesEvery model CreateObject accepts, with its hash and a flag for the LOD and proxy names that spawn invisible.
  • All 860 ped model namesEvery model GetHashKey resolves, with its hash and how many clothing components and props it carries.
  • Every GTA 5 zone nameAll 291 popzones across 44 districts, with the ids GET_NAME_OF_ZONE and GET_ZONE_FROM_NAME_ID use.