Stuck on a Roblox Studio script error? This guide covers the most common Luau errors โ nil values, wrong casing, infinite loops โ and how to fix them fast.
When a script errors in Roblox Studio, the Output window shows something like:
ServerScriptService.MyScript:12: attempt to index nil with 'Value'
This tells you three things: the script name (MyScript), the line number (12), and what went wrong (attempt to index nil with 'Value'). Always check the Output window first โ it tells you exactly where to look.
This is the most common Roblox error. It means you're trying to access a property on something that doesn't exist.
Bad:
local cash = player.leaderstats.Cash -- crashes if leaderstats doesn't exist yet cash.Value = 100
Good:
local leaderstats = player:FindFirstChild("leaderstats")
if leaderstats then
local cash = leaderstats:FindFirstChild("Cash")
if cash then
cash.Value = 100
end
endAlways check if something exists before using it. Use FindFirstChild instead of dot notation when the object might not exist.
You're calling something as a function when it's nil โ usually a wrong method name.
Bad:
local part = workspace:findFirstChild("KillBrick") -- lowercase, won't workGood:
local part = workspace:FindFirstChild("KillBrick") -- correct casingRoblox APIs are case-sensitive. findFirstChild, getService, waitForChild โ all wrong. Use FindFirstChild, GetService, WaitForChild.
-- BAD - freezes Studio immediately
while true do
print("hello")
end
-- GOOD - runs every second without freezing
while true do
task.wait(1)
print("hello")
endAlways put task.wait() inside while loops. Without it, the loop runs millions of times per second and freezes everything.
You're accessing a property or child that doesn't exist on that object.
-- Error: 'Health' is not a valid member of Player
player.Health = 0 -- wrong, Health is on the Humanoid
-- Correct
local humanoid = player.Character and player.Character:FindFirstChild("Humanoid")
if humanoid then humanoid.Health = 0 endLocalScripts only run in certain places:
- StarterPlayerScripts โ
- StarterGui โ
- StarterCharacterScripts โ
- Inside a Tool โ
- ServerScriptService โ (won't run here)
- Workspace โ (won't run here)
If your LocalScript isn't doing anything, check where it is.
-- BAD - might run before the RemoteEvent exists
local myEvent = ReplicatedStorage.MyEvent
-- GOOD - waits until it exists
local myEvent = ReplicatedStorage:WaitForChild("MyEvent")Use WaitForChild in LocalScripts when getting things from ReplicatedStorage. The server creates them, but the client might load before they're ready.
Old Roblox tutorials use wait() and spawn(). These are deprecated โ use the modern versions:
wait(1) -- old, avoid task.wait(1) -- correct spawn(myFunc) -- old, avoid task.spawn(myFunc) -- correct
If you've got a broken script and can't figure out what's wrong, try our AI Script Fixer. Paste your script and it'll identify the exact issues and return a corrected version.
Browse our free library of copy-paste Luau scripts โ no setup needed.
Browse Script Library โ