I'm just going to answer your question under Nexus's answer - there's not enough room in the comment feature.
You probably noticed that number
has to be assigned a value when the function is called on line 6. If you don't assign it a value, it just equals nil.
In your case, Nexus assigned it the integer 2, causing the output to print 2.
Some events, however, have built in parameters that you don't need to assign values to.These parameters will always equal the same thing.
Touched events have a single built in parameter equal to the part that did the touching. This is commonly named hit
, because it's the part that hit the other part, but you can name it whatever you want. For example, if we placed the following code inside a brick,
1 | function whenITouchThisBrick(partThatDidTheTouching) |
2 | print (partThatDidTheTouching.Name) |
4 | script.Parent.Touched:connect(whenITouchThisBrick) |
if your Left Leg touched the part that had this code inside it, the output would print "Left Leg". Notice that we never assigned an argument to the parameter partThatDidTheTouching
. We only connected the function to the Touched event. This is okay, however, because the Touched event will automatically give us the argument.
It plays no role in your script because you never use it.