In short
You made a local and nothing reads it afterwards. Script Analysis flags it because an unused variable is either leftover code or a sign of a bug, such as saving a value into one name and then using another. Delete it if you do not need it. If you must keep it, such as the second result of pcall you want to ignore, rename it with a leading underscore (_err, or just _) and the warning stops.
Variable,FunctionandImportare the same check for a local, a local function and a local holding arequire.- Check for a typo first: you may be reading a different name than the one you set.
- Prefix with
_only for values you are ignoring on purpose.
What the message means
Variable 'err' is never used; prefix with '_' to silence
Other forms of the same message:
Function 'helper' is never used; prefix with '_' to silenceImport 'Config' is never used; prefix with '_' to silence
Luau's linter tracks every local and reports the ones that are written but never read. Import is the name it uses for a local that holds the result of require, and Function is a local function nobody calls.
It is a warning, not an error, and the script runs. A name that starts with _ tells the linter "unused on purpose", which is why the message suggests it.
Causes and fixes
Three things cause this error in practice. Each one below has the smallest code that triggers it, then the fix.
- The value is stored in one name and read from another
- A result you want to ignore
- Leftovers from earlier code
The value is stored in one name and read from another
The most useful case of this warning: a typo or a rename left the real variable unused, and the code reads something else, often a global that is nil.
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
local startCoins = player:GetAttribute("StartCoins") or 0
-- Variable 'startCoins' is never used: the line below reads 'startcoins'
player:SetAttribute("Coins", startcoins)
end)
Use one spelling everywhere. Both warnings go away (this one and Unknown global 'startcoins'), and the player gets their coins instead of nil.
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player: Player)
local value = player:GetAttribute("StartCoins")
local startCoins = if typeof(value) == "number" then value else 0
player:SetAttribute("Coins", startCoins)
end)
A result you want to ignore
Some calls return two values and you only need one, such as pcall, which returns whether it worked and then the result or the error.
local DataStoreService = game:GetService("DataStoreService")
local store = DataStoreService:GetDataStore("Visits")
local ok, err = pcall(function()
store:IncrementAsync("total", 1)
end)
print("counted:", ok)
Better: use the error, so a failed save is not silent. If you truly do not need it, name it _.
local DataStoreService = game:GetService("DataStoreService")
local store = DataStoreService:GetDataStore("Visits")
local ok, err = pcall(function()
store:IncrementAsync("total", 1)
end)
if not ok then
warn("[Visits] could not count this visit:", err)
end
Leftovers from earlier code
A service fetched for code you removed, a module you no longer call, a helper function nobody uses. They do no harm, but they make the script harder to read and the warnings hide the ones that matter.
local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")
local function oldFade(part)
part.Transparency = 1
end
print(#Players:GetPlayers(), "players")
Delete what you do not use. Save a copy of the script first if you think you will want the old code back.
local Players = game:GetService("Players")
print(#Players:GetPlayers(), "players")
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. It lists warnings for every script in the place without running anything.
- Each row names the script and the line. Double-click it to open the script there.
- The same problem is underlined in the Script Editor; hover over the underline to read it.
Questions
Why does it not warn about my for loop variable?
Luau does not report unused loop variables, so for i, item in list do is fine even if you never use i. Many people still write _ there to show it is ignored.
Does an unused variable slow down my game?
Not in a way you would notice. The reason to fix it is clarity, and the bugs it sometimes points at.
Can I turn this warning off?
Name the variable with a leading _. To silence the check for a whole script, put --!nolint LocalUnused on the first line, but it is better to keep it on.
Can RoCode fix it?
Yes. Paste the warning into RoCode. It reads the script in your open place, fixes the typo if there is one, and removes or renames the leftovers.
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, 14 November 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 installed 12 November 2026) and reproduced with luau-analyze and luau-lsp on 14 November 2026. A type check catches misspelt APIs and wrong types, not game logic, so playtest in Studio before you publish.