First, understand how the Wait()
method works.
Wait()
will yield until an event fires. After that event fires, it stops yielding (it won’t continue to yield after the event fires). So, what it’s doing is that it continues to yield until you move the mouse, then once you do move the mouse, it stops yielding because the event has fired.
Here are a couple of examples:
Example 1
1 | script.Parent.Touched:Wait() |
Example 2
1 | script.Parent:GetPropertyChangedSignal( "Size" ):Wait() |
3 | print (script.Parent.Size) |
Both of the above examples will only work once. Wait()
stops yielding when the event occurs and the listener stops listening. Such is the behavior of the Wait()
method.
However, there are two exceptions:
- If the listener is within a function and it stops yielding after the event given has occurred, a new listener will be created with every function call.
- If the listener is within a
while
loop and the loop stops, the listener also stops. A new listener is created when the loop starts.
The second exception is likely why you are experiencing your situation. Hopefully you understand how it works.