Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Help with using the wait method on a signal?

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?

Image

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".

1 answer

✓ Accepted answer

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

15 comments

0

My own script isn't playing done in online. My place http://www.roblox.com/kevinnight45s-Place-Number-99-place?id=162582216 Check output in Server Console tab 

0

Oh, delay is just like wait and do I have to put delay?

2

Event objects don't have a 'state.' There's no way to tell if an event fired in the past. You can only tell if an event fires after you start listening to the event.

2

So your problem is that you are firing the event, and then after it fires, you are waiting for it to fire again. But it never does.

0

Not really i'm just wanting it to fire like a touched:wait() or like button1down:wait() and there is no purpose to this script I just wanted to learn about signals :s.

0

How would I start to listen to a event?

1

By nature, what event:wait() does is stop the current thread and waits for the event to be fired.

0

So,it works differently with signals? 

1

No, signals behave the same way as events.

0

I'm sorry,but I'm really confused so why isn't the wait part working?

1

It's working exactly as intended. The event is never being fired again. Think of it like firing a gunshot, and then waiting until you hear another gunshot. If no one fires another gunshot, you will be waiting forever.

0

So I changed some stuff(Updated Code above) and managed to print Done but firing the signal two times did I do it right?

1

How about you explain what you are trying to accomplish with your code?

0

I'm trying to make it print "Signal Fired","This is a connection" and "Signal wait","Done" by just firing  the signal once and using the wait method.Like you did on your example

This discussion is preserved as it was. New answers, comments, and votes are closed.