Help understanding the Touched event/ Events in general

Hello, I’m very confused about what is going on and I don’t know how to explain this properly but I’ll try. So I was scrolling through the Developer Hub on this article: Handling Events and I was confused about something. In the script below how do they manage to set the value of otherPart to myPart.Touched:Wait()?

Same thing in the following script. How do they manage to know what the other part is?

Simple, :Wait() just yields the code until event fires and returns it’s arguments which in this case Touched event returns the other part that came in contact with myPart.

For the :Connect() one event call the onTouched function with the other part that came in contact with part as the first argument.

1 Like

When a variable is defined inside of brackets () on the end of a function they are called parameters, it allows for functions to be more useable and accessable. If it wasn’t for parameters .Touched would be useless

:Wait() will be looping until the event fires and returns what touched the part.

So do events always return something?

It doesn’t necessarily need to be a function the Touched event.

It depends on the event, if there is nothing to return it returns nil (nothing)

It will wait until something touches the part in the Developer Hub example.

Depends on event you are talking about but yes, Touched event does return the other part that came in contact with the part every time it fires.

1 Like

While you’re here do you mind explaining why adding brackets next to the function we are calling makes the script not work?

image

Because adding brackets next to function will call them (or in another words, it would run the code inside them) instead of giving the reference to the :Connect() function so event can call the function when it fires.

1 Like