# Scripting a shooting range for FiveM

> Build a shooting range in FiveM: spawn target props, detect hits, run a timed scored round, reset targets and award licence progress server-side.

Source: https://fam-tools.com/guides/fivem-shooting-range-script · FAM Tools · published 2026-09-11 · updated 2026-09-11 · about 10 min

**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.

## Key points

- Targets are local props, spawned per round.
- Hit detection: `HasEntityBeenDamagedByEntity` + `ClearEntityLastDamageEntity`.
- Only run the per-frame loop during a round.
- The server checks score plausibility and location.
- Clean up props when the round ends.

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.

## A round in code

*client.lua*

```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*

```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](https://fam-tools.com/guides/fivem-weapon-license-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.

## 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.

## Related

- https://fam-tools.com/guides/fivem-weapon-license-system
- https://fam-tools.com/guides/fivem-weapon-anticheat-validation
- https://fam-tools.com/guides/fivem-give-weapon-to-player
- https://fam-tools.com/guides/fivem-weapon-shop-setup
