[HELP] Missing bytes

Hi, I have an missing bytes error when I do a callback in a serverevent.

Here’s the error:

Error running system event handling function for resource erp_core: citizen:/scripting/lua/scheduler.lua:39: Failed to execute thread: citizen:/scripting/lua/MessagePack.lua:830: missing bytes
stack traceback:
        [C]: in function 'error'
        citizen:/scripting/lua/MessagePack.lua:830: in method 'underflow'
        citizen:/scripting/lua/MessagePack.lua:465: in field 'any'
        citizen:/scripting/lua/MessagePack.lua:860: in field 'unpack'
        citizen:/scripting/lua/scheduler.lua:338: in local 'cb'
        economie/server.lua:148: in upvalue 'handler'
        citizen:/scripting/lua/scheduler.lua:124: in function <citizen:/scripting/lua/scheduler.lua:123>
stack traceback:
        [C]: in function 'error'
        citizen:/scripting/lua/scheduler.lua:39: in field 'CreateThreadNow'
        citizen:/scripting/lua/scheduler.lua:123: in function <citizen:/scripting/lua/scheduler.lua:92>

And my code:

-- client.lua
TriggerServerEvent('erp:pay', 50, function(cb)
	if cb == 1 then
		drawNotification(string.format(Lang['PayWithMoney'], 50))
		TriggerServerEvent('erp:changeOutfits', clotheshop.currentcat, button.composants, 0)
	elseif cb == 2 then
		drawNotification(string.format(Lang['PayWithBank'], 50))
		TriggerServerEvent('erp:changeOutfits', clotheshop.currentcat, button.composants, 0)
	elseif cb == 3 then
		drawNotification(Lang['NotEnoughMoney'])
	end
end)

-- server.lua
RegisterServerEvent('erp:pay')
AddEventHandler('erp:pay', function(amount, cb)
	local Source = source
	local steamid = getPlayerID(Source)
	local user = GetUser(steamid)
	if user.money - tonumber(amount) >= 0 then
		RemoveMoney(steamid, Source, amount)
		SaveMoney(steamid, user.money, user.dirty, user.bank)
		cb(1)
	elseif user.bank - tonumber(amount) >= -10000 then
		RemoveBank(steamid, Source, amount)
		SaveMoney(steamid, user.money, user.dirty, user.bank)
		cb(2)
	else
		cb(3)
	end
end)

Thanks for help :slight_smile:

That won’t work as that function reference won’t exist on the server. You’ll have to trigger another event to the client with your data.

1 Like

Did you find any way to fix that?