THE ORB
Starting the studio

Restarting a resource leaves threads, entities or handlers behind

Restarting a script left its old vehicles, characters or menus behind, so now there are two of everything.

groupsDuplicates after a restartcodeNeeds a developer

Do this first

A full server restart clears it. The script needs fixing so it cleans up after itself.

bug_reportPaste your whole console instead

What it means

/restart myres stops and starts the resource, but it does not undo what the resource did to the world. Threads are killed; spawned entities, NUI focus, blips, peds and anything registered elsewhere are not. Restart it a few times and you have several copies of everything.

The symptom is usually "it works until I restart it, then it does it twice".

What causes it

Ordered by how often it is the answer.

  1. 1

    Spawned entities are never cleaned up

    Peds, vehicles, objects and blips created at start, recreated on the next start, with the originals still there.

  2. 2

    NUI focus held at the moment of the stop

    The player is left unable to move with no UI on screen.

  3. 3

    Handlers registered in another resource

    A target zone or a command registered into a third-party resource stays registered.

  4. 4

    Threads that outlive the stop on the client

    A client thread keeps running until the client notices the resource stopped.

  5. 5

    Data written to a state bag or a global

    It persists; the next start adds to it.

How to tell which one is yours

Restart the resource twice and count. Two of a ped that should be one is the whole diagnosis.

Where to look

Everything created at resource start, and whether there is an onResourceStop that undoes it.

How to fix it

Every resource that touches the world needs a teardown:

local spawned = {}

AddEventHandler('onResourceStop', function(res)
    if res ~= GetCurrentResourceName() then return end
    for _, entity in ipairs(spawned) do
        if DoesEntityExist(entity) then DeleteEntity(entity) end
    end
    SetNUIFocus(false, false)
end)

Still stuck on your own code?

This page is what this error usually means. Paste your console into Server Fixer and it will rank everything in it and tell you what to do first, and if you would rather not touch it, ORBIE can repair the script and hand the resource back ready to drop in.

bug_reportOpen Server Fixer

Errors that travel with this one