So I found this cool way to a create custom event and I tried using the wait method on this event I made but it doesn't work why?
01 | Library = assert (LoadLibrary( "RbxUtility" )) |
02 | Signal = Library.CreateSignal() |
03 | Signal:connect( function () |
04 | print ( 'This is a connection' ) |
05 | print ( 'Signal wait' ) |
06 | Signal:wait() |
07 | print ( 'Done' ) |
08 | end ) |
09 | print ( 'Signal fired' ) |
10 | Signal:fire() |
11 | print ( 'Signal fired once,again' ) |
12 | Signal:fire() |
Do I have to fire the signal twice in order to make the wait work and how can I just fire it once to print 'done'?
Output:
Signal fired
This is a connection
Signal wait
Signal fired once,again
Done
This is a connection
Signal wait
I just want it to print:
Signal fired
This is a connection
Signal wait
Done
I just want to fire the event once so it can print "done".
I ran the script in Studio in the command bar and it worked. You fired the event, and called Signal:wait(), so it's going to wait until the event fires again.
Here's a clearer example of how it works:
01 | Library = assert (LoadLibrary( "RbxUtility" )) |
02 | Signal = Library.CreateSignal() |
03 |
04 | --in 2 seconds, fire the event |
05 | delay( 2 , function () |
06 | print ( "Firing" ) |
07 | Signal:fire() |
08 | end ) |
09 |
10 | print ( "Waiting for fire" ) |
11 | Signal:wait() |
12 | print ( "Done waiting" ) |
Output:
Waiting for fire
Firing
Done waiting