I don't understand it because in this particular script, "hit" is not repeated in the body:
function onTouched(hit) local t = script.Parent:findFirstChild("Torso") if t ~= nil then t.CFrame = CFrame.new(27, 40, 2)--input position in the () end end
script.Parent.Touched:connect(onTouched)
Btw this doesn't work, and I got it from a model.
Sorry, you should use a Code Block next time when posting code because this is very hard to read. It's the little Lua Bubble.
Like this
Anyways, I am still pretty new to scripting but i'll give this my best shot. A Parameter is a variable inside a function. And an argument is the Value that this Variable is set to. Here:
-- number is the parameter. function blah(number) print(number) end blah(2) -- 2 is the argument.
You should check the wiki for this type of stuff its got all sorts of info.
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.
function blah(number) print(number) end blah() --Output: 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,
function whenITouchThisBrick(partThatDidTheTouching) print(partThatDidTheTouching.Name) end 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.