Timing listeners using BindableEvents won't fire?
I have this BindableEvent named "AddListener". It's parented to my timing script, which listens for these events and triggers the callback given when the time specified is reached. The signature is AddListener:Fire(id, triggerTime, cb)
. The first parameter is an identifier for the listener so I can remove it later if needed, kind of like with ContextActionService:BindAction. The second parameter is the number of minutes after midnight when the third parameter, the callback, should be executed.
This is the timing script:
02 | local AddListener = Instance.new( "BindableEvent" ) |
03 | AddListener.Event:Connect( function (id, triggerTime, cb) |
05 | [ "triggerTime" ] = triggerTime, |
09 | AddListener.Parent = script |
10 | local RemoveListener = Instance.new( "BindableEvent" ) |
11 | RemoveListener.Event:Connect( function (id) |
14 | RemoveListener.Parent = script |
19 | game.Lighting:SetMinutesAfterMidnight(min) |
20 | local actualTime = wait( 60 / minRate) / ( 60 / minRate) |
21 | for i, v in pairs (listeners) do |
22 | if v.triggerTime > min and v.triggerTime < min + actualTime then |
24 | print ( "executed timing listener with id " .. i) |
27 | min = min + actualTime |
This is the listener, from another script:
1 | local sss = game:GetService( "ServerScriptService" ) |
2 | local addListener = sss.TimingScript:FindFirstChild( "AddListener" ) or sss.TimingScript:WaitForChild( "AddListener" ) |
3 | addListener:Fire( "test" , 60 , function () |
Both of these are server scripts. No errors are thrown, but neither of the print statements are ran.