RBXScriptSignal:Wait() should be changed to include an argument

I don’t know the general appeal for a feature like this, so this is a shot in the dark. Bear with me.

I think the :Wait() method of RBXScriptSignals ( i.e. part.Touched:Wait()) should accept a number argument that defines the maximum wait time until it just gives up and returns nil.

An example of when to use this:
There’s a part in a game where the player has to run and eventually make it to some goal area. There’s an invisible wall that has no collisions, and it listens to a touch event. If the player makes it to this part, they are safe, but if they don’t make it there in 5 seconds, they die.

The code to create this solution with my idea here would be:

--assume there's stored character variable, Character
local Part = SafePart.Touched:Wait(5)
if not Part then
Character:BreakJoints()
end

Simple enough. Feedback?

8 Likes

I would definitely use it, have to work around with spawns and loops atm.

When this was suggested previously I wrote a function that does what you are asking.

3 Likes

I would also like to wait for a specific return as well…

Use the search feature to search for similar threads:

See discussion on those pages.

This suggestion won’t work generically for all events: in case an event returns no arguments there is no way to distinguish between a timeout or an event actually being fired with just this suggestion. So I wouldn’t approve of this addition simply because there’d be exceptions to the rule that aren’t properly handled.

The workaround linked by Merely above seems elegant enough, and you can modify that to properly distinguish between a timeout or actual event.

PS: this is typically a client feature, it doesn’t apply to just Studio

1 Like