im trying to make a script that will find what day it is and then it will find the certain date in my case 12/25/18 Christmas, it will show how many days are left.
Is there a way to Find the date and subtract that untill its a certain date?
Yes you can. Lua has an os
library with two functions that are especially useful for this. os.date
and os.time
.
(hey kiddo press that "accept answer" button if this helped)
We can use os.date
to get the current date. If we pass "*t"
as the first argument for os.date
it will return a table instead of a string. Using this we can get the current time of the client. Now how do we get the day of christmas? Well christmas is on the 25th day of the 12th month on the xth
year. All we need to do is create a dictionary with those corrosponding values. For our xth
year we can use the index .year
from our previously defined table that got the current time for the client.
Now what do we do with these two tables? We can use os.time
to get the time since epoch and get a time stamp. We can subtract these time stamps and get how many seconds these days are apart. There are 24 hours a day and 60 minutes a hour and 60 seconds a second. We can divide our seconds by 24 * 60 * 60
which can be shortened to 24 * 60^2
to get our time till christmas in days!. Now we can just round up or down. If you divide by 60 you get the difference in minutes, and if you divide by 60^2 you get the time in hours.
local nowTable = os.date("*t") --// gets the time now local christmas = { --// creates table for christmas date year = nowTable.year, month = 12, day = 25 } local nowStamp = os.time(nowTable) --// get time stamp for now local christmasStamp = os.time(christmas) --// get the time stamp for christmas local timeDifference = (christmasStamp - nowStamp) --// get seconds between now and christmas print(timeDifference) --// Will output roughly "585562" depending where you live.
Uncopylocked place where you can test this code and edit it if you want. https://www.roblox.com/games/2661304390/time-till-christmas
Hello. I may have a solution to your issue you are dealing with.
Here is what you can do.
I don't think you can gather the date and time from ROBLOX Studio from a Script. But you can possibly try updating it every day and change the days on how long it is until Christmas.
If you're trying to give gifts everyday as an advent calendar sort of like CB:RO, then do this exact same thing, but insert gifts and points into the script. For e.g.(game.Players.LocalPlayer.leaderstats.Points = game.Players.LocalPlayer.leaderstats.Points + 1000).
But once again, I'm not too sure you can identify the date through a script, sorry.