[FiveM Server] - GetAllVehicles() not working on some Windows/Linux Versions

Hi everyone,

I’ve encountered a strange behavior with the Lua Function GetAllVehicles() using OneSync on the server-side in my scripts.
It seems that this function is only working on some versions of Windows, and it’s not working on any Linux distributions (that I’ve tested).

1. Client (production/canary) and FXServer version
Bug affects Server only: Tested with Various Builds, (for example Build 3922)
2. What you expected to happen
Expected a Vehicle Count greater than 0
3. What actually happens
Vehicle Count always 0 for some OS (see below tested OS Versions)
4. Category of bug (eg. client, server, weapons, peds, native)
Server
5. Reproducible steps, preferably with example script(s)
Example Script (server-side):

-- Count Total Cars
local count = 0
for _, car in pairs(GetAllVehicles()) do
	count = count + 1
end
print(("Count: %d"):format(count))

Test Result

  • Windows Build 1909 (Dev Tools, Workstation) - Working
  • Windows Build 2004 (Fresh Install, incl. VC-Redist64bit) - Working
  • Windows Build 20H2 (Fresh Install, incl. VC-Redist64bit) - Vehicle Count is 0
  • Windows Build 21H1 (Fresh Install, incl. VC-Redist64bit) - Vehicle Count is 0
  • Linux Ubuntu 18.04 (Fresh Install) - Vehicle Count is 0
  • Linux Ubuntu 20.04 (Fresh Install) - Vehicle Count is 0
  • Linux Debian 10 (Fresh Install) - Vehicle Count is 0

It seems odd, that this Lua Function is only working for some specific versions of Windows.

Any help is highly appreciated!
Thanks everyone!

After double checking if OneSync is actually enabled on these servers. Would it be possible to also print the length of the encoding, e.g.:

local encodedString = Citizen.InvokeNative(0x332169f5, Citizen.ResultAsObject())
...
print(("Count: %d, Encoding: %d"):format(count, #encodedString))
1 Like

Hi gottfriedleibniz,

Thank you very much for your quick reply!
And also big thanks for pointing out if OneSync is actually enabled!

I’ve been working as a Senior Software Developer for 15 years, and I still cannot believe how I forgot to check, if an option I enabled is actually enabled.

I started the server with this command line:

~/FXServer/run.sh +exec server.cfg +onesync on

But apparently, OneSync wasn’t enabled. I had to enable it in my server.cfg too. Go figure that :smiley:

Regarding the Windows 10 Server. I’ve used the Setup Wizard, but this time I chose to “use an existing folder”, and I forgot to check if onesync is configured in default/config.json.
And lo and behold, the onesync entry was indeed missing on those servers.

I’ve spent countless hours trying to fix this problem, and I still cannot believe the solution was so simple.

Thanks a lot!

Test Results
Just for completeness, I used your script and added the GetConvar() function for “onesync”, to debug this issue.

-- Count Total Cars
local count = 0
for _, car in pairs(GetAllVehicles()) do
	count = count + 1
end

local encodedString = Citizen.InvokeNative(0x332169f5, Citizen.ResultAsObject())
local onesync = GetConvar("onesync")
print(("Count: %d, Encoding: %d, OneSync: %s"):format(count, #encodedString, onesync))

This was the result (after fixing the OneSync option):

Windows 2004
Count: 7, Encoding: 36, OneSync: on

Ubuntu 20.04
Count: 15, Encoding: 76, OneSync: on

Ubuntu 18.04
Count: 5, Encoding: 26, OneSync: on

Windows 10 20H2
Count: 16, Encoding: 83, OneSync: on

Lessons learned

  • Check the generated config.json when using the Setup Wizard on Windows
  • Make sure you have “set onesync on” in your server.cfg if you are using Linux