Os.time() and os.date()'s seconds not changing at the same time tick()'s seconds changes

os.time() and os.date("!*t").sec increments to the next second when tick() has not yet.
For example, os.time() could be 1 and tick() could be 1 one moment and the next return value of os.time() could be 2 and tick() could still be something like 1.9, or tick() could be at 2 and os.time() still be at 1.

This occurs when a second is about to pass, and the bug occurs almost all if not all of the time.
To reproduce it, you can run

local lastSecondsInTick = math.floor(tick())
local lastSecondsInDate = os.date("!*t").sec
local tickSecondsChanged, dateSecondsChanged = false, false
while tickSecondsChanged == dateSecondsChanged do
    tickSecondsChanged, dateSecondsChanged =
        math.floor(tick()) ~= lastSecondsInTick,
        os.date("!*t").sec ~= lastSecondsInDate
    if tickSecondsChanged ~= dateSecondsChanged then
        warn(lastSecondsInDate, lastSecondsInTick, math.floor(tick()), os.date("!*t").sec)
    lastSecondsInTick, lastSecondsInDate = math.floor(tick()), os.date("!*t").sec

I tried this in studio, once on a place I’m working on and tried it on a new empty baseplate. I also tried going into one of my games, opening the developer console, and running the code on the server, and all of them has the issue.

I found this bug yesterday (8/21/19), but I’ve never tested or needed this to work before I found it.
I’m on Windows 10 Home, not tested on any other operating system (aside from what operating system Roblox uses to run games)

This topic was automatically closed after 12 minutes. New replies are no longer allowed.