Skip to content
TimeReferenceNew · 0.744

Stopwatch.new

Create a stopped stopwatch.

Details#

Creates a stopwatch with zero accumulated time and IsRunning = false. Call Start to begin measuring. ElapsedTime returns a Duration. Stopping preserves the elapsed total; starting again adds another interval. Reset clears the total and leaves the stopwatch stopped.

Fields Stopwatch#

FieldTypeMeaning
IsRunningbooleanTrue while the stopwatch is running; false after construction, Stop or Reset.
ElapsedTimeDurationAccumulated elapsed time, including the current interval while running. Each read returns a duration value; read again for a fresh measurement.

Signature#

Luau
Stopwatch.new(): Stopwatch

Returns#

A new, stopped Stopwatch with zero elapsed time.

Examples#

Local example

Luau
local watch = Stopwatch.new()
print(watch.IsRunning) -- false
watch:Start()
-- Perform your local work here.
watch:Stop()
print(watch.ElapsedTime.Milliseconds)

Notes#

  • ElapsedTime is a Duration: read .Seconds, .Milliseconds or another duration field. A saved ElapsedTime value does not update itself.