As a Roblox developer, it is currently too hard to wait for one of N events to fire without writing a horrible while
loop. For instance, one may have a function that needs to wait for an event to fire, but the process behind that event may be able to cancel at any time. Such a scenario that I have come across is using Humanoid.MoveToFinished
, but Humanoid.MoveToFinished
can be put on indefinite hold if one just calls Humanoid:Move(Vector3.new(x, y, z))
.
My proposed solution is something along the lines of a new wait
function, perhaps called waitForFirstSignal
. This function would accept a tuple of RbxScriptSignal instances, and yield until the first one was fired. Example:
local moveToCancelled = Instance.new("BindableEvent")
--Some more code
Humanoid:MoveTo(Vector3.new(x, y, z))
waitForFirstSignal(Humanoid.MoveToFinished, MoveToCancelled.Event)
Of course, this specific example could be fixed by having MoveToFinished
fire whenever anything interrupts the MoveTo
method, but I have come across other examples where this would be useful.