# Position Fix

{% hint style="info" %}
The purpose of this fix is to ensure that when users disconnect while inside of an interior, they’ll be teleported to the property entrance upon reconnecting.
{% endhint %}

## ESX

For ESX users, this should work as expected, a dedicated function has been added to handle this process automatically. You don't need to make any changes.

{% hint style="warning" %}
If the player still spawns in an incorrect location, please report the issue by opening a ticket or reaching out through our Discord server.
{% endhint %}

If you use a custom spawning or multicharacter plugin, you can create your own reconnect fix to prevent from users spawning in wrong areas. Use the code below as a reference!

```
RegisterNetEvent("housing:resetPlayerBucket", function()

    local src = source
    local identifier = GetPlayerIdentifier(src)
    if not identifier then return end

    exports.oxmysql:execute('SELECT name, coords, userinhere FROM housing', {}, function(houses)
        for _, house in ipairs(houses or {}) do
            local list = house.userinhere and json.decode(house.userinhere) or {}
            for i = #list, 1, -1 do
                if list[i] == identifier then
                    table.remove(list, i) 
                    exports.oxmysql:execute('UPDATE housing SET userinhere = ? WHERE name = ?', {
                        json.encode(list), house.name
                    })

                    -- Send back to entrance + clear bucket
                    SetPlayerRoutingBucket(src, 0)
                    local coords = json.decode(house.coords)
                    TriggerClientEvent('housing:returnOutside', src, coords)
                    TriggerClientEvent('premiumfurniture:forceStopFly', src)
                    return
                end
            end
        end
        SetPlayerRoutingBucket(src, 0)     
    end)
end)

```

## QB

This will prevent players from respawning at their last location if they were inside a property.

<figure><img src="/files/aG7AQdbkq3pNKW4hupqL" alt=""><figcaption><p>(Example for default qb-spawn)</p></figcaption></figure>

Simply add this to whichever `qb-spawn` compatible resource you're using.

```
    if type == "current" then
        QBCore.Functions.TriggerCallback("housing:getSafeSpawnOverride", function(coords)
            PreSpawnPlayer()
            TriggerServerEvent("housing:resetPlayerBucket")
            if coords then
                SetEntityCoords(PlayerPedId(), coords.x, coords.y, coords.z)
                SetEntityHeading(PlayerPedId(), coords.w or 0.0)
            else
                QBCore.Functions.GetPlayerData(function(pd)
                    SetEntityCoords(PlayerPedId(), pd.position.x, pd.position.y, pd.position.z)
                    SetEntityHeading(PlayerPedId(), pd.position.a or 0.0)
                end)
            end
    
            FreezeEntityPosition(PlayerPedId(), false)
            TriggerServerEvent('QBCore:Server:OnPlayerLoaded')
            TriggerEvent('QBCore:Client:OnPlayerLoaded')
            PostSpawnPlayer()
        end)
    end
```

## Other Framework

As for other framework, you have a function `TriggerCallback("housing:getSafeSpawnOverride", function(coords)`  that allows user to teleport back to the entrance of the property. And `TriggerServerEvent("housing:resetPlayerBucket")` for resetting the bucket.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://789.gitbook.io/789/items/premium-properties/position-fix.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
