Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Do Events provide built-in arguments?

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.

4 comments

0

Yes. Many events have built in parameters.

0

If you look at the wiki page for the event it does show what parameters it has.

0

Most of these things we don't think about. We just take them for granted because they just work.

0

No, not everything has it's own parameter. For example Mouse1Click doesn't have a parameter for the player.

1 answer

✓ Accepted answer

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!

1 comment

0

Does every Event have its own argument? Even ones like ChildAdded?

This discussion is preserved as it was. New answers, comments, and votes are closed.