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:
function Frap(Goo) Goo.BrickColor = BrickColor.new("Camo") end 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:
function PrintMe(messagetoprint) print(messagetoprint) end 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
script.Parent.Touched:connect(function(hit) --So easy. 3 lines. hit.BrickColor = BrickColor.new(0) --Black end
Script 2
hitparts = {} --21 lines. ermgosh. local count = 0 while wait() do for _,parts in pairs(workspace:GetChildren()) do 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 count = count+1 hitparts[count] = parts end end end function onTouch(hit) hit.BrickColor = BrickColor.new(0) --Turn the part to black end while wait() do for _,touched in pairs(hitparts) do onTouch(touched) end 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!