In short
The parentheses () run a function. This error says the thing in front of them was nil, so there was no function to run. Check the spelling (capitals count), check that the function is defined above the line that calls it, and for a ModuleScript, check that the function is put in the table the module returns.
- The message does not name the function. Click the error, look at the line, and check each name followed by
(on it. - For a method call with a colon, such as
Shop:Buy(), Luau names it:attempt to call missing method 'Buy' of table.
What the message means
ServerScriptService.Shop:14: attempt to call a nil value
Other forms of the same message:
attempt to call missing method 'GiveCoins' of table
When Luau reaches giveCoins(player), it looks up giveCoins, then calls it. If the lookup found nothing, the value is nil, and calling nil is this error. Luau cannot tell you the name you meant, so the message stays short.
Roblox objects are different: calling a method that an Instance does not have, such as part:Destroyy(), fails with Destroyy is not a valid member of Part instead.
Causes and fixes
Four things cause this error in practice. Each one below has the smallest code that triggers it, then the fix.
- The name is misspelt or has different capitals
- The function is defined below the line that calls it
- A ModuleScript does not put the function in its table
- A method is called with a colon but defined with a dot, or is missing
The name is misspelt or has different capitals
Luau names are case-sensitive: givecoins, GiveCoins and giveCoins are three different names. A name that was never defined reads as a global that is nil.
local function giveCoins(player, amount)
print(player, amount)
end
-- capital G: this name was never defined
GiveCoins("Builderman", 10)
Use the exact name the function was defined with. The Script Editor underlines an unknown name in orange (Unknown global) before you even press Play, so look for that underline.
local function giveCoins(playerName: string, amount: number)
print(playerName, amount)
end
giveCoins("Builderman", 10)
The function is defined below the line that calls it
A local function exists only from its own line down. Code above it cannot see it, so the name there means a global that is nil. It works in some scripts only because the call happens later, inside an event.
-- runs before the function below exists
setUpShop()
local function setUpShop()
print("shop ready")
end
Define functions at the top of the script and call them at the bottom. If two functions call each other, declare the name first with local name, then assign it.
local function setUpShop()
print("shop ready")
end
setUpShop()
A ModuleScript does not put the function in its table
Other scripts only see what a ModuleScript returns. A function made with local function inside the module, and never added to the returned table, is nil to everyone else.
local Shop = {}
local function buy(itemName)
print("bought", itemName)
end
return Shop
-- in another script: require(Shop).buy("Sword") -> attempt to call a nil value
Add the function to the table the module returns, then call it through that table.
local Shop = {}
function Shop.buy(itemName: string)
print("bought", itemName)
end
return Shop
Then require(ReplicatedStorage.Shop).buy("Sword") works from any script that can see ReplicatedStorage.
A method is called with a colon but defined with a dot, or is missing
Shop:buy() looks up buy on Shop and passes Shop as the first argument. If the table has no buy, the message is attempt to call missing method 'buy' of table. If it has one defined with a dot, the call works but every argument shifts by one place.
local Shop = {}
function Shop.Buy(itemName)
print("bought", itemName)
end
-- the table has Buy, not buy: attempt to call missing method 'buy' of table
Shop:buy("Sword")
Match the name exactly, and match how it is defined: a function defined with . is called with ., one defined with : is called with :.
local Shop = {}
function Shop.Buy(itemName: string)
print("bought", itemName)
end
Shop.Buy("Sword")
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 Output (Window menu, or the Script tab), clear it with Ctrl+K (⌘K on Mac), and press Play.
- Find the first red line. It starts with the script's place in the Explorer and the line number, such as
ServerScriptService.Shop:12:. - Click the red line. Studio opens that script with the cursor on the failing line.
- Read the lines between
Stack BeginandStack Endunder it: they list the calls that led there, newest first, so you can see which function called the broken one. - Still not sure which value is wrong? Add
print(typeof(x), x)just above the line, or set a breakpoint on it and read the values in the Watch window.
Questions
Which function is nil? The message does not say.
Click the error to open the line, then check every name that is followed by (. Put print(typeof(name)) just above the line for the one you are unsure of: it prints nil for the culprit.
Why does it say attempt to call missing method instead?
Because the call used a colon, like Shop:buy(). Luau then knows the name and says attempt to call missing method 'buy' of table. The fix is the same: the table has no function with that exact name.
My function is in a ModuleScript. Why is it nil?
The module must add it to the table it returns, for example function Shop.buy() before return Shop. A local function inside the module is private to it.
Can RoCode fix it?
Yes. Paste the Output line into RoCode. It reads the script and any module it requires in your open place, finds the missing or misspelt function and fixes the call or the definition.
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 by running the broken code with the Luau command line tool and against the message strings in Roblox Studio itself on 23 October 2026. A type check catches misspelt APIs and wrong types, not game logic, so playtest in Studio before you publish.