How can I measure the time that has passed from a point to 5 seconds?

How can I measure the time with a cycle that is repeated many times and I need to use the time (without pausing the code) to verify that at least 5 have passed and if so, the condition is met to proceed with the system?

You can use os.time() for this. os.time() returns the time in seconds since the Unix epoch.

Here’s an example of what the code will look like:

local pointInTime = os.time()

print("Some code here")

if os.time() - 5 >= pointInTime then
    print("Enough time passed")
end

Note: we subtract 5 from the current time because you asked for 5 seconds

1 Like

You can use os.clock for that.

local before = os.clock()

-- insert code here

warn(os.clock - before .. " SECONDS HAVE PASSED!")

From what I can see from a lot of forum posts, os.time() is actually the way to go, mostly because os.clock() is based on the CPU time. My bad.