This tutorial is my attempt to document Roblox’s many time-related features. This is in no way comprehensive, or even well-polished, so suggestions and feedback are more than welcome. If you have relevant use cases, caveats, notes or really anything, please reply.
- 1 microsecond = 1/1,000,000th of a second
- 1 millisecond = 1/1,000th of a second
Getting time
os.time()
- Returns the number of seconds since the UNIX epoch
- Accurate to 1 second
os.clock()
- Returns the number of seconds of CPU time used by a program
- Accurate to ~1 microsecond
tick() - Deprecated
- Returns the number of seconds since the UNIX epoch, on the computer the code was ran on (i.e., do not assume this will be synced across clients or the server)
- Accurate to 1 second (precision is ?)
- See this post for deprecation info,
tick()
has large discrepancies and an alternative should almost always be used
time()
- Returns the number of seconds since the game began on the computer the code was ran on (i.e., this will not be synced across clients or the server).
- Accurate to 1/240th of a second (updated every 1/240th, precision may be more)
elapsedTime()
- Returns the number of seconds since Roblox started running
- Accurate to 1 millisecond
- Inconsistent behavior across OSes, can be extremely outdated on mobile
workspace:GetServerTimeNow()
- Returns the number of seconds since the server began (synced across both client and server)
- Accurate to 1 microsecond
workspace.DistributedGameTime
- Returns the number of seconds since the game has been running on the computer the code was ran on (i.e., this will not be synced across clients or the server).
- Accurate to 1/60th of a second (updated every 1/60th, precision may be more)
DateTime.now().UnixTimestamp
- Returns the number of seconds since the UNIX epoch
- Accurate to 1 second
DateTime.now().UnixTimestampMillis
- Returns the number of milliseconds since the UNIX epoch
- Accurate to 1 millisecond
RunService.Heartbeat(deltaTime)
-
deltaTime
Returns the number of seconds since the last frame - Accurate to 1/240th of a second (updated every frame as a parameter of
Heartbeat
)
RunService.Stepped(time)
-
time
returns the number of secondsRunService
has been running - Accurate to ?
RunService.Stepped(time, deltaTime)
-
deltaTime
returns the number of seconds since the last frame - Accurate to 1/241th of a second (updated every frame as a parameter of
Stepped
)
RunService.RenderStepped(deltaTime)
-
deltaTime
Returns the number of seconds since the last frame - Accurate to ? (updated every frame, precision is ?)
Using time
os.difftime(t2, t1)
- Returns the difference between two times,
t2
andt1
must be integers representing seconds since the UNIX epoch - Due to
t2
andt1
’, this is accurate to 1 second
Thanks
-
@Quenty’s excellent reply: Luau Recap: June 2020 - #14 by Quenty
-
zeuxcg’s clarifications on Quenty’s reply: Luau Recap: June 2020 - #16 by zeuxcg
-
@Planet_Dad’s post: Os.time() vs. tick() vs. os.clock() vs.?
-
@Ethanthegrand14’s post: Is there any real difference between os.time() and tick()?
-
@roby336’s post: Simple to learn notes on time() / tick(), For animation or movement scripts and so forth
-
@round_edsquare for pointing out info on
tick()
-
Roblox’s many documentation pages