I have done some testing, and after findings such as this and example 2, I have pretty much come to the conclusion that many Events have built-in values that they can give to arguments.
However, I was not able to find anything on the Wiki about this. Can anyone confirm this claim for me, and possibly add any additional information they know about it (such as which Events have arguments to give)
Example 2: In a script inside a Part, write:
1 | function Frap(Goo) |
2 | Goo.BrickColor = BrickColor.new( "Camo" ) |
3 | end |
4 | script.Parent.Touched:connect (Frap) |
When the player touches the Part, whatever touched it will turn to the color Camo. Even though Goo was never actually defined when the function was called, Touched gave a value to it.
It's kinda like this code:
1 | function PrintMe(messagetoprint) |
2 | print (messagetoprint) |
3 | end |
4 |
5 | PrintMe( "This is a test" ) --It will print "This is a test". connect basicly just does this whole argument thing by itself. Like a little mini-script helper that just comes and gives you the arguments without you needing to find them yourself. |
I think that events do have their own arguments because of the :connect() part. Compair Script1 to 2. (I know script 2 is wrong. It's just to give an idea.) Script 1
1 | script.Parent.Touched:connect( function (hit) --So easy. 3 lines. |
2 | hit.BrickColor = BrickColor.new( 0 ) --Black |
3 | end |
Script 2
01 | hitparts = { } --21 lines. ermgosh. |
02 | local count = 0 |
03 |
04 | while wait() do |
05 | for _,parts in pairs (workspace:GetChildren()) do |
06 | if parts:IsA( "Basepart" ) and math.abs(parts.Position.X)-math.abs(script.Parent.Position.X) = = 1 or math.abs(parts.Position.Y)-math.abs(script.Parent.Position.Y) = = 1 or math.abs(parts.Position.Z)-math.abs(script.Parent.Position.Z) = = 1 then |
07 | count = count+ 1 |
08 | hitparts [ count ] = parts |
09 | end |
10 | end |
11 | end |
12 |
13 | function onTouch(hit) |
14 | hit.BrickColor = BrickColor.new( 0 ) --Turn the part to black |
15 | end |
The connect is a RBXScriptSignal. When you use the connect, if you're doing a touched script, it would make a RBXScriptConnection object. This object returns the part you touched in this case.
Yes, events do have their own arguments thanks to RBXScriptConnection!