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

how to I wait () RBXScriptSignal for a specific time?

The title may be a bit unclear, but you know how wait() functions go with events?

RBXScriptSignal:wait() -- Pauses the script until event is fired

Lets say I want to only wait up to 180 seconds until that event is fired. Also I want to connect the same function to the wait time, so even after 180 seconds pass, I can fire that function too (Even if the event doesn't fire).

Do you have any suggestions?

1 comment

0

I would search at devforum for an answer.

1 answer

My idea is to just use a

while wait() do
end

type loop, that breaks either when time is out or when the event happens.

local happened = false
con = Event:connect(function() happened = true end)
	-- record that the event happened
local stopTime = tick() + 180 -- 180 seconds from now...
while tick() < stopTime do
	wait()
	if happened then
		break
	end
end
con:disconnect() -- clean up the old connection

Another, weirder, but briefer option would be to make a BindableEvent and set up both things to fire it, then destroy the connection/bindable event:

local e = Instance.new("BindableEvent")
local c = Event:connect(e:Fire()) -- when the event happens
delay(180, function() e:Fire() end) -- in 180 seconds
e.Event:wait() -- the sooner of the two
c:disconnect() -- cleanup the connection

1 comment

0

I swear I remember games Like Roblox Battle using Bindable Events to set up their game rotation system. I think I'll try that.

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