Implementing custom events. How would I go around the :Wait() method?

I’m trying to create custom events without using something such as a BindableEvent, and I have been able to do this. So far :Connect() is implemented.

The problem I came to was implementing :Wait() because I have to be able to pause either the script or thread that the script which called :Wait() and unpause it when the event is fired.

My first thought was repeating wait() until the event is fired, but before even trying I thought that this would be a bad idea, even if it worked. Surely there’s a more efficient method for going around this?

So you want to have a delay but you don’t want to stall the entire script?

I probably should have explained a little more.

My custom events thing is a metatable inside of a module script called Utils. This metatable has three methods and two fields. The methods are Connect (connects a function to be called when the event is fired), Wait (waits until the event is fired before running any code after the statement), and _Fire (fires the event).

I need to find a way to pause the thread or script that called the Wait method and unpause is when _Fire is called (so when the event fires). My problem is mostly that I have no idea how to get whatever script my function is being called from, so I can’t yield it.

I pretty much just need to find that and then I think I can figure out where to go from there.

So basically a :pause function and :unpause function?

In the same way the .Touched event implements Wait for example. I can try and attach a gif showing the behaviour I want.

Yeah, the only way I could think of that happening is with a repeat until.

The gif should show what behaviour I am trying to get. It will not run any code after the :Wait() method until the event is fired.

Maybe you’re right. I might try reposting this with an improved title; if I don’t get any other answers I think I may just have to go with that, unfortunately.

With custom events, you can try encapsulating a bindable event. I was using this one before, you can check it out Signal.lua · GitHub