[Need help] Script / syntax error - different every time, and sometimes script works fine

Hi there. I’m getting different script errors from different plugins sometimes when I join my dev server. The problem is it sometimes works just fine, and the errors differ all the time.
Unlike my previous problem [Help] Same client script works when hosted on localhost, but breaks on linux which has been resolved, server doesn’t crash during cache creation, nothing else indicates there’s something wrong.
Most of the errors make no sense:

Creating script environments for QC_vrp_charcreator
Error loading script menus.lua in resource QC_vrp_charcreator: @vrp/lib/utils.lua:46: error parsing module vrp/lib/Proxy:[string "vrp/lib/Proxy.lua"]:20: syntax error near '}'

So it says there’s syntax error in vrp proxy library, which I’m using without any modifications, as published at https://github.com/ImagicTheCat/vRP/tree/1.0 and used without any problems by hundreds of other people.

Here are some of the other errors I’m getting:

SCRIPT ERROR: citizen:/scripting/lua/scheduler.lua:199: bad argument #1 to 'unpack' (table expected, got nil)
> [global chunk]^7 (^5@vrp/lib/utils.lua^7:67)
> fn^7 (^5@vrp/client/quadcore.lua^7:79)
SCRIPT ERROR: citizen:/scripting/lua/scheduler.lua:199: bad argument #1 to 'unpack' (table expected, got nil)
> [global chunk]^7 (^5@vrp/lib/utils.lua^7:67)
> fn^7 (^5@vrp/client/quadcore.lua^7:79)

Just to clarify things, the exact same function on vrp/client/quadcore.lua:79 works fine randomly after several re-joins, and sometimes breaks without any changes to code (tested on multiple Debian 9 and Windows hosts, multiple PCs, different server builds 29XX).

[     48172] [    GTAProcess]                11932/ QC: Starting charcreator
[     53953] [    GTAProcess]                11932/ ^1SCRIPT ERROR: [string "vrp/lib/Proxy.lua"]:33: attempt to call a nil value (global 'async')^7
[     53953] [    GTAProcess]                11932/ ^3> BuildMenu^7 (^5@QC_vrp_charcreator/menus.lua^7:344)
[     53953] [    GTAProcess]                11932/ ^3> createCamera^7 (^5@QC_vrp_charcreator/client.lua^7:525)
[     53953] [    GTAProcess]                11932/ ^3> createInitial^7 (^5@QC_vrp_charcreator/client.lua^7:504)
[     53953] [    GTAProcess]                11932/ ^3> f^7 (^5@QC_vrp_charcreator/client.lua^7:131)
[     53953] [    GTAProcess]                11932/ ^3> handler^7 (^5rp/lib/Tunnel.lua^7:143)
[     36312] [    GTAProcess]                 6516/ Uncaught SyntaxError: missing ) after argument list (@vrp/gui/lib/libopus.wasm.js:1)
[     31406] [    GTAProcess]                14532/ Uncaught ReferenceError: libopus is not defined (@vrp/gui/AudioEngine.js:31)
[     32937] [    GTAProcess]                10732/ Error loading script @vrp/lib/utils.lua in resource QC_vrp_charcreator: @vrp/lib/utils.lua:43: error loading module vrp/lib/Debug:@vrp/lib/utils.lua:46: error parsing module vrp/lib/Tools:[string "vrp/lib/Tools.lua"]:32: 'end' expected (to close 'if' at line 26) near 'e'
[     32937] [    GTAProcess]                10732/ stack traceback:
[     32937] [    GTAProcess]                10732/ 	@vrp/lib/utils.lua:46: in function 'module'
[     32937] [    GTAProcess]                10732/ 	[string "vrp/lib/Debug.lua"]:2: in main chunk
[     32937] [    GTAProcess]                10732/ 	[C]: in function 'xpcall'
[     32937] [    GTAProcess]                10732/ 	@vrp/lib/utils.lua:38: in function 'module'
[     32937] [    GTAProcess]                10732/ 	@vrp/lib/utils.lua:56: in main chunk
[     32937] [    GTAProcess]                10732/ stack traceback:
[     32937] [    GTAProcess]                10732/ 	[C]: in function 'error'
[     32937] [    GTAProcess]                10732/ 	@vrp/lib/utils.lua:46: in function 'module'
[     32937] [    GTAProcess]                10732/ 	[string "vrp/lib/Debug.lua"]:2: in main chunk
[     32937] [    GTAProcess]                10732/ 	[C]: in function 'xpcall'
[     32937] [    GTAProcess]                10732/ 	@vrp/lib/utils.lua:38: in function 'module'
[     32937] [    GTAProcess]                10732/ 	@vrp/lib/utils.lua:56: in main chunk
[     32937] [    GTAProcess]                10732/ stack traceback:
[     32937] [    GTAProcess]                10732/ 	[C]: in function 'error'
[     32937] [    GTAProcess]                10732/ 	@vrp/lib/utils.lua:43: in function 'module'
[     32937] [    GTAProcess]                10732/ 	@vrp/lib/utils.lua:56: in main chunk
[     32937] [    GTAProcess]                10732/ Failed to load script @vrp/lib/utils.lua.
[     32937] [    GTAProcess]                10732/ Error loading script client.lua in resource QC_vrp_charcreator: @vrp/lib/utils.lua:46: error parsing module vrp/lib/Tunnel:[string "vrp/lib/Tunnel.lua"]:21: syntax error near '<\135>'
[     32937] [    GTAProcess]                10732/ stack traceback:
[     32937] [    GTAProcess]                10732/ 	@vrp/lib/utils.lua:46: in function 'module'
[     32937] [    GTAProcess]                10732/ 	@QC_vrp_charcreator/client.lua:2: in main chunk
[     32937] [    GTAProcess]                10732/ stack traceback:
[     32937] [    GTAProcess]                10732/ 	[C]: in function 'error'
[     32937] [    GTAProcess]                10732/ 	@vrp/lib/utils.lua:46: in function 'module'
[     32937] [    GTAProcess]                10732/ 	@QC_vrp_charcreator/client.lua:2: in main chunk
[     32937] [    GTAProcess]                10732/ Failed to load script client.lua.
[     28922] [    GTAProcess]                12148/ Error loading script menus.lua in resource QC_vrp_charcreator: @vrp/lib/utils.lua:46: error parsing module vrp/lib/Proxy:[string "vrp/lib/Proxy.lua"]:20: syntax error near '<\18>'
[     28922] [    GTAProcess]                12148/ stack traceback:
[     28922] [    GTAProcess]                12148/ 	@vrp/lib/utils.lua:46: in function 'module'
[     28922] [    GTAProcess]                12148/ 	@QC_vrp_charcreator/menus.lua:1: in main chunk
[     28922] [    GTAProcess]                12148/ stack traceback:
[     28922] [    GTAProcess]                12148/ 	[C]: in function 'error'
[     28922] [    GTAProcess]                12148/ 	@vrp/lib/utils.lua:46: in function 'module'
[     28922] [    GTAProcess]                12148/ 	@QC_vrp_charcreator/menus.lua:1: in main chunk
[     28922] [    GTAProcess]                12148/ Failed to load script menus.lua.

I am also seeing player spawned event being triggered 3 times in a row sometimes, which leads to some scripts breaking. The server has +set onesync on launch parameter.
There’s message in client console onesync: Dropping duplicate player for netID 1 (slotID 128).


QC: Triggered SetCustomization was triggered 3 times (should be triggered once upon first spawn, and usually it does work, but sometimes triggers 3 times randomly).

Chemical Town plugin shows me joining 3 times with same ip but different port:


Any help greatly appreciated.

Your missing a comma or bracket in that table, check the format of the table and once that’s fixed test it. A lot of those errors that are expecting tables, if they use that proxy table then they would throw back the table expected, got nil errors

This would break every time, for everyone using vrp then.
I only get this errors 1 out of 10 joins during 1 day, 6 out of 10 joins the other day - it’s pretty random.
P.S. I’ve checked the vrp scripts that give the error via automatic lua syntax checker, same with scripts I’m working on - no errors whatsoever.

I did some research and found out all this mess is most likely caused by 2 bugs (probably not connected to each other).

  1. vrp is sometimes started 2 times clientside after player re-joins server without restarting FiveM (currently don’t have a repro for this).
  2. LoadResourceFile native doesn’t work as intended when used clienside. It returns some random jibber-jabber when used for loading lua files, moreover, it’s different for the same .lua file each time you re-join the server, and running code received using it somehow works sometimes, but sometimes gives syntax errors.

My repro for checking what LoadResourceFile returns:

  1. Use vrp 1.0 (tested on debian 9)
  2. Add “lib/utils.lua” to the files section in __resource.lua so it can be read clientside using LoadResourceFile. Other files from lib folder are already included there.
  3. Either add files from this repository inside the vrp (and include them in the vrp __resource.lua), then add the files which are going to be checked to the settings.lua (example below) or use the cache-verification as a standalone plugin (set the files to be loaded from vrp).

settings.lua example:

FilesHashesToVerify = {
	{resource = GetCurrentResourceName(), file = "lib/utils.lua", v = false}, -- filename and "v", this will be used on the server
	{resource = GetCurrentResourceName(), file = "lib/Tunnel.lua", v = false},
	{resource = GetCurrentResourceName(), file = "lib/Proxy.lua", v = false},
	{resource = GetCurrentResourceName(), file = "lib/Debug.lua", v = false},
	{resource = GetCurrentResourceName(), file = "lib/Luaseq.lua", v = false},
	{resource = GetCurrentResourceName(), file = "lib/Tools.lua", v = false},
}

Actual result:


crc32 hash of .lua file loaded with LoadResourceFile differs on server and client, it also changes on client after re-join, the .lua file itself sometimes throws syntax errors.

Easier repro for the same bug, courtesy of Chase#6741 provided in cfx.re discord:

- test-resource/test.class.lua – defined as client script in fxmanifest

print("blah blah blahbber")

- second-test-resource/client.lua

local data = LoadResourceFile("test-resource","test.class.lua")
print(data)

output

�/o�>`�    Ma��o�q��e���i�c_]�����/�Zx����TȞ�ʚ��LՏ?�֣�b�~���nA���ywc��`�m����9����o�%^�| �M?eHfWhW�Ս̈́�)�Fê�S�ld�e���%�S�iuJ�9��a=��Ӥh���X;wҡ}���a�b    �w�"a�GM�.Å��.^qy�NPk�e�o�}FW^S��!�6��%.�.do�`����Z�@ҿɮ�
T�р��H�S������������R
1 Like