What does this line mean?

I am decent with scripting, but this line is confusing me, can someone please explain it. Clearly it gives the current day, but please explain the string.sub and the parameters so i can understand better. Thanks:

local currentDay = string.sub(os.time(), 1, 3)

it takes the first 3 characters of os.time()

This is nonsense, and doesn’t do anything useful that I can tell. os.time() returns a number of seconds.

To clarify more, the next few lines of code are this:

		local currentDay = string.sub(os.time(), 1, 3)
		if currentDay == "Thu" then --thursday
			badgeService:AwardBadge(player.UserId, badgeId)
		end

And yes it wasn’t making sense to me either, so I thought i would ask the forum.

os.time() returns a number like 1662396278
string.sub(os.time(), 1, 3) returns string with the first three numbers like "166"

I don’t see how that would ever equal "Thu".

Here’s a way to actually do that:

local currentDay = DateTime.now():FormatLocalTime("ddd", "en-us")

You can also use :FormatUniversalTime() instead if you want it to be based on GMT instead of the user/server’s local timezone.

1 Like

Yes i just ran a print and saw that so i was confused… thanks for clarifying, I thought i was going nuts!

Technically would be based on UTC.

1 Like