FiveM 'attempt to concatenate a nil value' – Fix
The error
SCRIPT ERROR: @my-resource/server/main.lua:18: attempt to concatenate a nil value (local 'name')
What it means
Lua's .. operator can only join strings or numbers. The value named in the parentheses — here local 'name' — was nil. On FiveM this is usually a player who already left (GetPlayerName(src) returned nil), a config field you never filled in, a missing database column, or an event argument that never arrived so every later parameter shifted.
The fix
-- Instead of:
-- local msg = 'Welcome ' .. name
local name = GetPlayerName(src) or 'unknown'
local item = itemName or 'nothing'
local msg = ('Welcome %s, you bought %s'):format(name, item)
-- For SQL, do not join strings. Use placeholders:
MySQL.query('SELECT * FROM players WHERE citizenid = ?', { citizenid })
Read the whole line: a long join can have five operands and only one of them is nil. Give that value a fallback with or, return early if it is missing, or use string.format. If the value comes from an event, check the handler arguments match what the sender actually passes.
These steps are for creators and server owners working on their own scripts. Test the change on a development server or in Studio before you put it live.
Related tools: FiveM script generator · Fix a FiveM Lua error · all script generators