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?
Library = assert(LoadLibrary("RbxUtility")) Signal = Library.CreateSignal() Signal:connect(function() print('This is a connection') print('Signal wait') Signal:wait() print('Done') end) print('Signal fired') Signal:fire() print('Signal fired once,again') 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:
Library = assert(LoadLibrary("RbxUtility")) Signal = Library.CreateSignal() --in 2 seconds, fire the event delay(2, function() print("Firing") Signal:fire() end) print("Waiting for fire") Signal:wait() print("Done waiting")
Output:
Waiting for fire
Firing
Done waiting