Hey everyone! I see a lot of repeat posts regarding certain errors, which are typically considered quite common. So I decided I would make a reference sheet in case you ever forget what the heck is going wrong with your code. Lets begin!
Some necessary vocabulary if you dont already know:
Index : Means to find something in relation to something else.
Nil : Does not exist.
DataType : A kind of value. IE: Number, boolean, CFrame, Vector3, etc.
Argument : A value to pass to a function.
[color=red]" Expected ‘)’ (to close ‘(’ at line _), got ____ "[/color]
There is a parenthesis missing from your code! The most common occurence of this
is when writing an event connection with a function in it:
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function()
print("A player joined the game!")
end <--- A parenthesis should be here! The brother is right after :Connect .
[color=red]" Attempt to perform arithmetic (___) on number and ____ "[/color]
This means you tried to perform math on a number and an incompatible value, such as
a boolean (true or false).
In the first set of parenthesis, it will tell you what kind of mathematical operation that was attempted.
For example:
mul : means multiplication
div : means division
add : means addition
sub : means subtraction
Make sure you are doing mathematical operations with compatible datatypes!
[color=red]" Invalid argument #1 ( ___ expected, got ___ ) "[/color]
This is also a value incompatibility issue. It will appear when trying to pass an incorrect data type
into a function, or when setting a value to an incompatible type.
In other words, a value you are passing into a function/value is not the kind of value that function/value receives.
For example:
math.clamp(true, 4, 10)
--[[ This will error, saying:
" invalid argument #1 to 'clamp' (number expected, got boolean) "
because the first argument in math.clamp() is always a number! ]]
math.clamp(8, 4, 10)
--[[ The fisrt argument in math.clamp() is a number, so this works! ]]
As well as:
workspace.Baseplate.Position = true
--[[ Position is a Vector3 value, and cannot be true. This will error. ]]
workspace.Baseplate.Position = Vector3.new(23,51,30)
--[[ Position is being set to a Vector3 value. This works! ]]
[color=red]Attempt to index nil with ‘____’[/color]
The cause of this is most commonly associated with using :FindFirstChild() .
For example:
workspace:FindFirstChild("Cat").Parent = workspace.Baseplate
--[[ We are trying to set the parent of 'Cat' to the baseplate.
But wait, 'Cat' does not exist! That means :FindFirstChild() will return nil.
When we try to find, or 'index', something related to 'Cat' (it's parent), it
will tell us we are attempting to index nil, or find a part of something that
doesnt exist.
[color=red]Missing argument # _[/color]
This is fairly straight forward. You called a function, but didnt pass a required value to it.
The argument number is whichever argument appears in the defined order of the specific function.
For example:
math.clamp(1, 0, 10)
--[[ math.clamp() takes 3 arguments. A number, and a minimum and maximum.
What if we only pass 1 argument? ]]
math.clamp(1)
--[[ This will error, with a message along the lines of "Missing argument #2".
You can see we passed the 1st argument, but the 2nd is nowhere to be seen!
[color=red]" ____ is not a valid member of ____ "[/color]
This occurs when you set a variable to be an object, and then try to find, or index, something in
that object that does not exist.
For example:
local Baseplate = workspace.Baseplate
print(Baseplate.Cow)
--[[ There is no object or property within Baseplate called Cow,
so this will error. ]]
If there are any other common errors I’ve missed, let me know and I’ll add them to the list. One error I am aware of that isnt exactly common is the “Unable to cast to token.” I’m not entirely sure what the conditions are for this to happen. Something to do with enums IIRC? If you have an explanation for it, I’d love to hear it.