Massive "CreateVehicle" native issues

Hello,
before diving into my issue, here’s an overview of my server environment:

Server Environment
OS: Windows
Artifacts: b11535
DLC Level: 3258
Framework: ESX 1.10.10
Startup Arguments: +set sv_enforceGameBuild 3258 +set onesync_population false
OneSync: On (with infinity)
Caching Proxy: Yes

Other configuration variables

set sv_requestParanoia 1
set sv_filterRequestControl 0
set sv_experimentalNetGameEventHandler false
sets sv_pureLevel 1
set rateLimiter_stateBagFlood_rate 350
set rateLimiter_stateBag_rate 350
set rateLimiter_stateBag_burst 450

Problem
For quite some time now, I’ve been experiencing significant issues with multiple garage systems and other resources that utilize the client-side CreateVehicle native.

Although this issue occurs infrequently, it’s persistent enough to frustrate both players and admins. I haven’t been able to identify the root cause.

Symptoms:

  • Occasionally, the CreateVehicle function fails to spawn the vehicle entity.
  • The issue appears to bypass checks such as:
RequestModel(ModelHash)
if not IsModelInCdimage(ModelHash) then return end

and

while not HasModelLoaded(ModelHash) do
Wait(0)
end

These checks return “true” even when the vehicle model does not spawn.

  • Players must reconnect to the server to restore vehicle spawning functionality.
  • Add-on vehicles are predominantly affected, though vanilla vehicles have also shown this behavior.

Troubleshooting Steps Taken

  • checked AntiCheat configuration, disabled any vehicle or entity related checks
  • updated artifacts
  • updated other resources like ox_lib
  • Tested several methods for spawning vehicles and verifying model loading:
    using ox_lib
local success, result = pcall(function()
    return lib.requestModel(model, 5000)
end)

using native functions

if not IsModelInCdimage(ModelHash) then return end
RequestModel(ModelHash) 
                                    
while not HasModelLoaded(ModelHash) do -- Waits for the model to load
   Wait(0)
end
                                    
LKW = CreateVehicle(ModelHash, spawnCoords.x, spawnCoords.y, spawnCoords.z , heading, true, false)
SetModelAsNoLongerNeeded(ModelHash)

or using ESX’s SpawnVehicle functionality

RequestModel(model)
while not HasModelLoaded(model) do
   Wait(0)
end
ESX.Game.SpawnVehicle(model, vector3(spawnCoords.x, spawnCoords.y, spawnCoords.z), spawnCoords.w, function(spawnedVeh)
(...)
end)
SetModelAsNoLongerNeeded(model)

I’ve had limited success using CreateVehicleServerSetter for server-side spawning. However, this is not a viable long-term solution, as it introduces other issues, such as:

  • Problems setting vehicle properties.
  • Entity ownership changes occurring within a single tick.

So, I am currently really really confused and need urgent help fixing this problem.
I’d greatly appreciate your guidance. Thanks!

With onesync if the spawn location is out of range of the client it will fail to spawn. Could you clarify what occasions it occurs with?

Spawn location is never out of range. Its maximum 5-10 meters distance from player.

It occurs incredibly randomly. Sometimes it works, sometimes it doesn’t work at all. The players have to reconnect to be able to spawn vehicles again. I’m beginning to fear that it could be a caching problem. However, this has been cleared several times on both the client and server side.

Alright, have you validated the entity handle for the “created” vehicle? Printing the handle, and checking it against DoesEntityExist(handle)?
Also, just a thought, do you know if you use routing buckets AT ALL.

I never did that, yet.
I’m using routingbuckets, yes but not related to any cars or spawning them.

I would still recommend switching to the server side and adapting the other systems, as the client side is simply not up to date and everything is much easier on the server side.

ESX also offers a server-side method:
ESX.OneSync.SpawnVehicle(model, coords, heading, properties?, cb?).

And the garage system? Is that inside an MLO? Because that could also cause problems.

1 Like

Switching to server side is not really possible since some bought scripts are still escrowed and do not offer any server side alternative. And, as said before, CreateVehicleServerSetter function comes with its own “bugs”. JGScripts (dev of my garage system) wrote some things about that and its issues. Why are you not using CreateVehicleServerSetter by default? | JG Scripts Docs

None of any vehicle spawn points is inside any interieur / mlo.

Anyways, the issue still persists and I really cannot find any cause. It’s really really annoying.