In short
Studio checks your scripts as you type. Unknown global 'playr' means the name playr is used but was never defined anywhere the line can see. It is shown in the Script Analysis window and as an orange underline, before you even press Play. When the script runs, that name is nil, so it usually turns into attempt to index nil or attempt to call a nil value. Fix the spelling, or define the name with local where the line can see it.
What the message means
Unknown global 'playr'
Other forms of the same message:
Unknown global 'x'; consider assigning to it first
A global is a name not declared with local. Roblox provides a few (game, workspace, script, task, print and so on). Any other name that is not a local in scope is unknown, and Script Analysis warns about it.
It is a warning, not an error: the script still runs. That is what makes it worth reading, because it points at the bug before the game breaks.
Causes and fixes
Three things cause this error in practice. Each one below has the smallest code that triggers it, then the fix.
- A typo in a variable name
- A local is used outside the block that made it
- A service is used without GetService
A typo in a variable name
One letter is enough: playr for player, Workspace works but WorkSpace does not.
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
-- Unknown global 'playr'; at runtime: attempt to index nil with 'Name'
print(playr.Name .. " joined")
end)
Fix the spelling. Accepting the Script Editor's autocomplete for names avoids this entirely.
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player: Player)
print(player.Name .. " joined")
end)
A local is used outside the block that made it
A local only exists from its line to the end of its block (function, if, for, do). Using it after the end makes it an unknown global there.
local part = workspace:WaitForChild("Lamp")
if part:IsA("BasePart") then
local brightness = 2
end
-- brightness only existed inside the if: Unknown global 'brightness'
print(brightness)
Declare the variable before the block, then set it inside.
local part = workspace:WaitForChild("Lamp")
local brightness = 0
if part:IsA("BasePart") then
brightness = 2
end
print(brightness)
A service is used without GetService
Only game and workspace are globals. Players, ReplicatedStorage, TweenService and the rest must be fetched into a local first; code copied from another script often misses that line.
-- copied without its first line: Unknown global 'ReplicatedStorage'
local remote = ReplicatedStorage:WaitForChild("BuyItem")
print(remote)
Add the GetService line at the top of the script.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remote = ReplicatedStorage:WaitForChild("BuyItem")
print(remote)
Fix it in your place
Paste the error, RoCode fixes it in your place
Copy the line from Output and paste it here. RoCode opens the script it names in the place you have open in Studio, works out which of the causes above it is, and edits the code there instead of handing you a snippet to paste.
RoCode is an AI agent for Roblox Studio: it reads the scripts in the place you have open, finds the line and edits it there, and every change is an undo point. It runs on Windows or macOS with a desktop browser. Free to start, with free credits every day.
How to find the line that causes it
- Open Script Analysis from the View tab. Each row names the script, the line and the unknown name.
- Double-click a row to open the script at that line.
- In the Script Editor, the name is underlined in orange. Hover over it to read the warning.
Questions
Does Unknown global stop my script?
No, it is a warning from Script Analysis, and the script still runs. But the name is nil at runtime, so the line will usually fail with a red error once it is reached.
What does consider assigning to it first mean?
You are reading a global that the script never sets. If you meant a new variable, declare it with local name = value before the line that uses it.
Why is Players unknown but game is not?
game and workspace are built-in globals. Services such as Players must be fetched with local Players = game:GetService("Players").
Can RoCode fix it?
Yes. Paste the warning into RoCode. It reads the script in your open place, works out which name you meant and fixes the spelling, the scope or the missing GetService line.
Sources and further reading
How the code was checked: every block marked Fixed passes Luau's strict type checker against Roblox's API definitions (luau-lsp, 23 October 2026), and every block marked Breaks compiles and fails only when it runs. The message wording was checked against the message strings in Roblox Studio itself (macOS build of 13 October 2026) on 23 October 2026. A type check catches misspelt APIs and wrong types, not game logic, so playtest in Studio before you publish.