Also, what unit of time does the tick() function return the UNIX Epoch in?
It is seconds since the epoch in UTC.
Developers can use the machine time to -- simply -- measure time as accurately as possible. The task scheduler uses the machine time to calculate the time difference between updates and uses that time to decide which actions to resume. Roblox's wait function returns the time it actually took to yield the thread -- that's passed in by the task scheduler. The RunService's events send the time delta between frames -- that's calculated with the machine time.
On other platforms you might not be provided with such events, in which case you need to calculate the delta yourself.
You'll eventually face situations where you'll be wondering: "how can I make this as accurate as possible?" Often there are multiple approaches, one of them is you using the machine time directly.
Say you want to calculate a packet's Round Trip Time (sender machine -> receiver machine -> sender machine):
local sendTick = tick()
RemoteFunction:InvokeServer()
local elapsedTime = tick() - sendTick
In the previous case, there is no simple solution using wait/RunService.
Sometimes you want to know the time it took to complete an action that takes an unknown amount of time (maybe to simply collect data), for example, a server-wide matchmaker:
local mmStartTick = tick()
repeat
until opponentFound or playerCancelled
local mmEndTick = tick()
local mmElapsedTime = mmStartTick - mmEndTick
A simple timer could however be made with just the wait function:
local timeElapsed = 0
while true do
timeElapsed = timeElapsed + wait()
print(timeElapsed)
end
The tick would of course work there as well.
2 comments
tick is used for randomness, it also is used to time how long it takes to perform actions (helps you see which method is more efficient, etc)
tick() returns from your local time (your computer lol)