im receving this error error parsing script @esx_zombiesystem/server/main.lua in resource esx_zombiesystem: @esx_zombiesystem/server/main.lua:35: 'then' expected near '='
code line 35 = if xPlayer ~= nil then
RegisterServerEvent('esx_zombiesystem:itemloot')
AddEventHandler('esx_zombiesystem:itemloot', function(item)
local xPlayer = ESX.GetPlayerFromId(source)
local random = math.random(1, 3)
if xPlayer ~= nil then
xPlayer.canCarryItem(item, random) then
xPlayer.addInventoryItem(item, random)
TriggerClientEvent("esx:showNotification", xPlayer.source, ('Você achou ~y~' .. random .. 'x ~b~' .. item))
else
xPlayer.showNotification('Você não pode pegá-lo porque seu inventário está cheio!')
end
end)
Replace that with this, as you can see it’s much easier to read and better handling expected output.
RegisterServerEvent('esx_zombiesystem:itemloot')
AddEventHandler('esx_zombiesystem:itemloot', function(item)
local xPlayer = ESX.GetPlayerFromId(source)
local random = math.random(1, 3)
if xPlayer == nil or not next(xPlayer) then
TriggerClientEvent('esx:showNotification', source, "~r~An error ocurred.");
return
end
if not xPlayer.canCarryItem(item, random) then
TriggerClientEvent('esx:showNotification', source, "~r~You can not carry that much.");
return
end
xPlayer.addInventoryItem(item, random)
TriggerClientEvent("esx:showNotification", source, ('Você achou ~y~' .. random .. 'x ~b~' .. item))
end)
If you get an error in the next part use this.
RegisterServerEvent('esx_zombiesystem:itemloot')
AddEventHandler('esx_zombiesystem:itemloot', function(item)
local xPlayer = ESX.GetPlayerFromId(source)
local random = math.random(1, 3)
if xPlayer == nil then
TriggerClientEvent('esx:showNotification', source, "~r~An error ocurred.");
return
end
if not xPlayer.canCarryItem(item, random) then
TriggerClientEvent('esx:showNotification', source, "~r~You can not carry that much.");
return
end
xPlayer.addInventoryItem(item, random)
TriggerClientEvent("esx:showNotification", source, ('Você achou ~y~' .. random .. 'x ~b~' .. item))
end)