ScriptsAboutBlogToolsKnowledge BaseReviewsFAQBasketDocsSupport
Luacrash

attempt to perform arithmetic on a nil value

Also seen as: arithmetic on a nil value attempt to perform arithmetic (field) nil arithmetic Lua

What causes it

Your code tried to do math (+, -, *, /) with a value that's nil. Usually a Config value, a table field, or a returned value that doesn't exist. The parentheses name what's nil.

How to fix it

Find the nil value named in the error and ensure it has a number before the math runs.

  1. Read the variable/field in parentheses — that's what's nil.
  2. If it's a Config value, confirm it's defined and the config loads before this code.
  3. If it's a returned value, check the function actually returned a number.
  4. Add a default: local n = value or 0 before the arithmetic.

Related errors

Related guides

Still stuck? We can help.

Optimized, dual-framework scripts for QBCore and ESX from Viper Development — escrow protected, delivered instantly to your Cfx portal.