diff --git a/[esx]/es_extended/client/functions.lua b/[esx]/es_extended/client/functions.lua index c789e572..00899115 100644 --- a/[esx]/es_extended/client/functions.lua +++ b/[esx]/es_extended/client/functions.lua @@ -489,6 +489,10 @@ function ESX.Game.SpawnVehicle(vehicle, coords, heading, cb, networked) print("Spawned Vehicle: " .. NetID) if NetID then local vehicle = NetworkGetEntityFromNetworkId(NetID) + while not DoesEntityExist(vehicle) do + vehicle = NetworkGetEntityFromNetworkId(NetID) + Wait(0) + end SetEntityAsMissionEntity(vehicle, true, true) SetVehicleHasBeenOwnedByPlayer(vehicle, true) SetVehicleNeedsToBeHotwired(vehicle, false) diff --git a/[esx]/es_extended/server/onesync.lua b/[esx]/es_extended/server/onesync.lua index 4ef8d465..0f0c1c54 100644 --- a/[esx]/es_extended/server/onesync.lua +++ b/[esx]/es_extended/server/onesync.lua @@ -61,18 +61,19 @@ end ---@param heading number ---@param cb function function ESX.OneSync.SpawnVehicle(model, coords, heading, autoMobile, cb) - if type(model) == 'string' then model = GetHashKey(model) end - local vector = type(coords) == "vector3" and coords or vec(coords.x, coords.y, coords.z) - if type(autoMobile) ~= 'boolean' then - return - end - local tries = 0 - local Entity = autoMobile and Citizen.InvokeNative(`CREATE_AUTOMOBILE`, model, coords.x, coords.y, coords.z, heading) or CreateVehicle(model, coords, heading, true, true) - while not DoesEntityExist(Entity) do - Wait(0) - end - local netID = NetworkGetNetworkIdFromEntity(Entity) - cb(netID) + if type(model) == 'string' then model = GetHashKey(model) end + local vector = type(coords) == "vector3" and coords or vec(coords.x, coords.y, coords.z) + if type(autoMobile) ~= 'boolean' then + return + end + CreateThread(function() + local Entity = autoMobile and Citizen.InvokeNative(`CREATE_AUTOMOBILE`, model, coords.x, coords.y, coords.z, heading) or CreateVehicle(model, coords, heading, true, true) + while not DoesEntityExist(Entity) do + Wait(0) + end + local netID = NetworkGetNetworkIdFromEntity(Entity) + cb(netID) + end) end ---@param model number|string