Problems with lua os

Hello, could someone explain to me what it is for you and how I could apply it :pray:

I’ve been learning with the documentation but I can’t make sense of it and how to use it

I would rlly really appreciate an explanation of this

os docs:
os (roblox.com)

os is a table that has multiple time related functions. Example uses:


local time1 = os.time() 

local CurrentTimeDict = os.date("*t",time1)

print(CurrentTimeDict) -- prints a dictionary of the current time, like the year, day, and week

print(time1) -- time since jan 1st, 1970, also known as unix epoch

CurrentTimeDict would look like this:

[“day”] = 16,
[“hour”] = 11,
[“isdst”] = true,
[“min”] = 56,
[“month”] = 10,
[“sec”] = 59,
[“wday”] = 7,
[“yday”] = 289,
[“year”] = 2021

1 Like

Oh I see! Thank you very much, but what is the purpose of this part?

Also os.clock() is a timer built into your computer that is a counter of seconds and is very accurate, this could be used for measuring the time taken for code to run or just a super accurate counter.

local computertime = os.clock() -- returns computer time usually accurate to the microsecond(0.000001)

1 Like

Synchronization. Its a global time variable not based on location in the world or time zone. It is useful for syncing cross server or even cross game things like timed events or shop refreshes like in Arsenal.

1 Like

You could also read this page on the UNIX time to get a better understanding:

1 Like

So is it a global time for everyone?

Thank you very much, you have helped me a lot, one last question, how could I use and in what cases would I use the os.difftime :open_mouth:

At a simple level, it just subtracts two different times put in the function.


print(os.difftime(100,90)) -- prints 10 because 100-90 = 10
1 Like

Would you use this to know the precise time between two players or something like that? :open_mouth:

What you could do is let the clients send remote events of their clients os.time and then use diff time to find the precise time.

1 Like

Thanks a lot! You have helped me a lot, now I understand everything :smiley:

1 Like