#Black screen when using `spawnLastLocation` in `qb-multicharacter`

1 messages · Page 1 of 1 (latest)

olive charm
#

What happens:

  1. The spawnLastLocation event depends on this callback:
QBCore.Functions.TriggerCallback('apartments:GetOwnedApartment', function(result)
    if result then
        -- all the spawn logic is inside here
    end
end)
  1. If the player doesn't have an apartment, result will be nil, and the spawn logic won’t run.

  2. Since everything depends on if result then, the player gets stuck on a black screen (or sees the sky), and the character is never fully loaded.

Cause:

Even if the player doesn’t have an apartment, the server still sends valid coords.
However, the current code unnecessarily blocks the spawn, requiring an apartment when it’s not actually needed.

Solution:

Remove the dependency on the apartment callback and use the received coordinates directly.

Fixed code:

RegisterNetEvent('qb-multicharacter:client:spawnLastLocation', function(coords, cData)
    local ped = PlayerPedId()
    SetEntityCoords(ped, coords.x, coords.y, coords.z)
    SetEntityHeading(ped, coords.w or 0.0)
    FreezeEntityPosition(ped, false)
    SetEntityVisible(ped, true)

    DoScreenFadeOut(500)

    local PlayerData = QBCore.Functions.GetPlayerData()
    local insideMeta = PlayerData.metadata['inside'] or {}

    if insideMeta.house then
        TriggerEvent('qb-houses:client:LastLocationHouse', insideMeta.house)
    elseif insideMeta.apartment and insideMeta.apartment.apartmentType and insideMeta.apartment.apartmentId then
        TriggerEvent('qb-apartments:client:LastLocationHouse', insideMeta.apartment.apartmentType, insideMeta.apartment.apartmentId)
    end

    TriggerServerEvent('QBCore:Server:OnPlayerLoaded')
    TriggerEvent('QBCore:Client:OnPlayerLoaded')
    Wait(2000)
    DoScreenFadeIn(250)
end)

Note: Since this is an unofficial fix, I don’t recommend replacing the original block directly.
Instead, you can comment out the original code and paste this version below for safety.

#

Black screen when using spawnLastLocation in qb-multicharacter

#

Edit:
This issue only occurs if the following configuration is set in qb-apartments/config.lua:

Apartments.Starting = false

When this is set to false, new players do not receive a default starter apartment, and the callback apartments:GetOwnedApartment returns nil.
As a result, the spawn logic inside spawnLastLocation is skipped, causing the black screen bug.

This fix ensures players can still spawn using the provided coordinates, even without owning an apartment.

meager patio
#

Seems like this would be better suited as a PR

olive charm