Scheduler

Signals

Create your own events and connect functions to them.

A signal calls every connected function when it is fired. The built-in events (RunService.Heartbeat, mc.Events.Render, ...) are signals.

Signal.new()

Creates a new signal. This is the only function on the global Signal table.

local hit = Signal.new()

hit:Connect(function(who)
  print("hit by", who)
end)

hit:Fire("Steve")

Signal methods

signal:Connect(fn)

Calls fn every time the signal fires. Returns a connection. fn must be a function, otherwise an error is raised. Lowercase alias: signal:connect(fn).

signal:Once(fn)

Like Connect, but disconnects itself after the first call.

signal:Wait()

Pauses the current coroutine until the signal fires, then returns the values it was fired with.

local dt = RunService.Heartbeat:Wait()

signal:Fire(...)

Calls every connected function with ..., each in its own coroutine, and resumes everything waiting in Wait. Lowercase alias: signal:fire(...).

Connections

A connection is returned by Connect and Once.

Field or methodMeaning
Connectedtrue until the connection is disconnected
FunctionThe function that was connected
Disconnect()Removes the connection. Lowercase alias: disconnect()
local conn
conn = RunService.Heartbeat:Connect(function(dt)
  if something then
    conn:Disconnect()
  end
end)

Each connected function runs in its own coroutine, so one function can use task.wait without delaying the others, and an error in one does not stop the others.