Utilities

Timing and input

Time, Tween and Keybinds.

Time

Time helpers. They measure time with os.clock().

Time.now()

Returns os.clock().

Time.stopwatch()

Returns a stopwatch that is already running.

MethodMeaning
sw.elapsed()Seconds counted so far
sw.stop()Pauses it
sw.start()Resumes it
sw.reset()Sets it back to zero and starts it

Time.cooldown(seconds)

Returns a cooldown object.

MethodMeaning
cd.ready()true if the cooldown has passed
cd.use()If ready, starts the cooldown and returns true. Otherwise returns false
cd.remaining()Seconds left
cd.reset()Makes it ready again
local cd = Time.cooldown(0.5)
RunService.Heartbeat:Connect(function()
  if cd.use() then
    print("fires at most twice a second")
  end
end)

Time.throttle(fn, interval)

Returns a function that calls fn at most once per interval seconds. Calls in between are ignored.

Time.debounce(fn, wait)

Returns a function that calls fn only after wait seconds have passed without another call.

Time.every(interval, fn)

Calls fn every interval seconds. Stops when fn returns false. Returns a function that stops it.

Time.waitFor(condition, timeout, step = 0.05)

Pauses until condition() is true. Returns true, or false if timeout seconds pass first.

Time.retry(fn, tries = 3, delay = 0.5)

Calls fn(attemptNumber) until it does not error. Returns true, result, or false, lastError after the last try.

Time.format(seconds)

Returns HH:MM:SS.

Tween

Tween.new(from, to, duration, easing, onStep, onDone)

Animates a number from from to to over duration seconds, once per frame.

  • easing is a function, or a name from mathx.ease. Default is linear.
  • onStep(value, alpha) is called every frame. alpha goes from 0 to 1 and value is the current number.
  • onDone() is called at the end.

Returns a table with cancel().

Tween.new(0, 100, 1.5, "outCubic", function(v)
  bar.Size = Vector2.new(v, 10)
end)

Keybinds

Runs functions when keys are pressed. Keys are checked once per frame. Key names are the strings used by UserInputService.

Keybinds.bind(key, fn, mode = "press")

Registers a bind and returns its ID. Modes:

Modefn is called
"press"With no arguments when the key goes down
"toggle"With true or false each time the key goes down
"hold"With true when the key goes down and false when it is released

Keybinds.toggle(key, fn), Keybinds.hold(key, fn)

Shortcuts for the "toggle" and "hold" modes.

Keybinds.unbind(id)

Removes one bind.

Keybinds.clear()

Removes all binds.

Keybinds.toggle("R", function(on)
  Modules.setEnabled("Sprint", on)
end)