Unknown global 'plr'in Roblox Luau: what it means and how to fix it

What it means

Script Analysis found a name that was never defined. It shows as an underline in the editor before you run anything. If the line runs, the name is nil.

The same warning also shows up as:

  • Unknown global 'plr'; consider assigning to it first
  • W001: Unknown global 'player'

The smallest script that triggers it

Triggers the warningline 4: error here
local Players = game:GetService("Players")
 
Players.PlayerAdded:Connect(function(player)
  print(plr.Name)
end)

The fix

Fixedline 4: the fix
local Players = game:GetService("Players")
 
Players.PlayerAdded:Connect(function(player)
  print(player.Name)
end)

The function's parameter is called player. Using the same name everywhere means the variable exists where it is read.

Common causes

  1. A variable name is misspelled or shortened in one place.
  2. A local variable is used outside the block that declared it.
  3. A variable is used above the line that declares it.

Practice this until it sticks

A Deep Dive on variables 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.