attempt to call a nil valuein Roblox Luau: what it means and how to fix it

What it means

You put brackets after a name to call it as a function, but the name holds nil. Usually the function does not exist under that name at the moment the line runs.

The smallest script that triggers it

Triggers the errorline 1: error here
greet("Ada")
 
local function greet(name)
  print("Hello, " .. name)
end

The fix

Fixedline 5: the fix
local function greet(name)
  print("Hello, " .. name)
end
 
greet("Ada")

A local function only exists below the line that defines it, so the call has to come after the definition.

Common causes

  1. The function is called above the line that defines it.
  2. The function name is misspelled or has different capitals.
  3. A ModuleScript does not return the function you are calling, so the field on the required table is nil.

Practice this until it sticks

A Deep Dive on functions and scope: 5-minute lessons, each with a quiz. What you miss comes back in the next module. One Deep Dive a day is free. No card.