How do I use os.date?

So I’m trying to make a system where it prints something every time its 10 seconds into a minute, I wrote this code:

while task.wait(1) do
	print(os.date("%S"))
	if os.date("%S") == 10 then
		print("10 Seconds")
	end
end

It doesn’t print anything, how do I check what os.time(“%S”) is equal to?

1 Like

This link from the API docs sums it up pretty well. Looks like it returns the second.

Also. To fix your issue, os.date returns strings. You can see this by typing print(type(os.date("%S"))); into the command bar. Your refactored code should look like this:

while task.wait(1) do
	print(os.date("%S"))
	if os.date("%S") == "10" then
		print("10 Seconds")
	end
end

Would it be better to use tonumber or should I just reference the numbers with quotation marks

tonumber works pretty much as well.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.