How to find the thread or script a function is called in

I am trying to implement custom events, but I am struggling with the :Wait() method. I need to pause the thread or script that called the :Wait() method until the custom event is fired, but I would rather not use wait() until to implement this. The custom events metatable is stored in a module script called utils.

I thought what I could do instead is pause the thread that called the function, but I do not know how I would find the thread which called this function. Consequently, I am unable to pause it. Is there any way I can go around implementing this?

An example of the behaviour I want is shown below:

use part.Touched:Connect instead

part.Touched:Connect (function()
   print "Woah"

This would run multiple times for each body part that touches it so you can add a debounce that disconnects the connection once ran the first time as well.

You can try using debug.traceback(). It gives you the script and the line. However, it’s a string so you would have to do some formatting if you want to get the instance.