attempt to concatenate nil with stringin Roblox Luau: what it means and how to fix it

What it means

You joined two values with .. and one of them was nil. The message names the types in order: here the left side was nil and the right side was a string.

The same error also shows up as:

  • attempt to concatenate string with nil

The smallest script that triggers it

Triggers the errorline 2: error here
local playerName
print(playerName .. " joined the game")

The fix

Fixedline 1: the fix
local playerName = "Guest"
print(playerName .. " joined the game")

Only strings and numbers can be joined with .. so the variable needs a real value before the line runs.

Common causes

  1. The variable was never assigned, or was assigned inside an if block that did not run.
  2. A function that should return text reached its end without a return.
  3. A table field is misspelled, so reading it gives nil.

Practice this until it sticks

A Deep Dive on strings and concatenation: 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.