Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 8 years ago

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?

0
I would search at devforum for an answer. ErtyPL 129 — 2y

1 answer

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
8 years ago

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
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. randomsmileyface 375 — 8y
Ad

Answer this question