RBXScriptSignal:Wait(Timeout)

Not sure if this is possible with how it’s currently implemented on ROBLOX’s end, but it would be nice to have this. Pretty much, if a signal isn’t called after the Timeout, it should just continue the function and maybe return “false” or “Enum.ScriptSignal.Failed” (Doesn’t really matter)

I’m aware you can just implement it like this:

local waitTimeout do
	local resume = coroutine.resume
	local create = coroutine.create
	local wait = wait
	local unpack = unpack
	
	function waitTimeout(event, timeout)		
		local flag
		resume(create(function()
			flag = {event:Wait()}
		end))
		
		-- wait for flag to be set to true or fire bindable
		local time = 0
		while not flag and time < timeout do
			time = time + wait()
		end
		
		return unpack(flag)
	end
end

or return your own bindable timeout

But I trust ROBLOX with a more efficient implementation (if RBXScriptSignals for :wait() were the same as while not flag do wait() end then someone should make a PSA for it :stuck_out_tongue_winking_eye: )

1 Like

https://devforum.roblox.com/t/rbxscriptsignal-wait-int-timeout/53815
https://devforum.roblox.com/t/rbxscriptsignal-wait-should-be-changed-to-include-an-argument/35473/
https://devforum.roblox.com/t/timeout-argument-for-event-wait/32737
https://devforum.roblox.com/t/add-timeout-parameter-for-event-wait/31803

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.