Hello.
I made a simple date system that counts up from a given month and year, in this case it’s January, 2017. But I couldn’t really figure out how to have days in there as well. If anyone can at least guide me through that’d be really appreciated.
local months = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}
local DateConfig = game.ReplicatedStorage.DateConfig -- container for all the stringvalues
local day = DateConfig.Day
local month = DateConfig.Month
local year = DateConfig.Year
local rate = DateConfig.Rate
local seconds = rate.Value
while true do
for _, monthName in pairs(months) do
month.Value = monthName
wait(seconds)
end
year.Value = year.Value + 1
end
If the latter, you can create a dictionary containing how many days are in each month:
local months = {
January = 31
February = 28
March = 31
-- etc...
}
-- For leap years, we need to keep track of what year it is
local year = 2017
while true do
if year % 4 == 0 then
months.February = 29 -- If it's a leap year (which happens every 4 years) then set February to have 29 days
end
for month, amountDays in pairs(months) do
month.Value = month
for i = 1, amountDays do -- for i = day 1 to the amount of days in that month do
day.Value = i
wait(5)
end
end
year += 1
end
local months = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}
local DateConfig = game.ReplicatedStorage.DateConfig -- container for all the stringvalues
local day = DateConfig.Day
local month = DateConfig.Month
local year = DateConfig.Year
local rate = DateConfig.Rate
local seconds = rate.Value
while wait() do
for _, monthName in pairs(months) do
month.Value = monthName
wait(seconds)
end
year.Value = year.Value + 1
end
I modified this slightly since there were so many errors. But now it keeps going to random months instead of January, February, March, etc. Like it’s supposed to.
local months = {
January = 31,
February = 28,
March = 31,
April = 30,
May = 31,
June = 30,
July = 31,
August = 31,
September = 30,
October = 31,
November = 30,
December = 31
}
local DateConfig = game.ReplicatedStorage.DateConfig
local day = DateConfig.Day
local month = DateConfig.Month
local year = DateConfig.Year
while true do
if year.Value % 4 == 0 then
months.February = 29
end
for nextMonth, amountDays in pairs(months) do
month.Value = nextMonth
for i = 1, amountDays do
day.Value = i
wait(0.8)
end
end
year.Value = year.Value + 1
end
The reason your loop isnt in order is because looping in dictonaries dont go in order. The only solution I can think of is adding a seperate table with the ordered list, where you index the amount of days with the Name in the ordered table.
local order = {
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
}
for i,v in next, order do
print(v..". "..months[v])
end
Where v is the index or name and months[v] is the value or amount of days
local months = {"January", 31, "February", 28, "March", 31} --Finish table, month comma days
local DateConfig = game.ReplicatedStorage.DateConfig
local day = DateConfig.Day
local month = DateConfig.Month
local year = DateConfig.Year
while true do
for i, month in ipairs(months) do
if i % 2 == 1 then
month.Value = month
for i = 1, months[i + 1] do
day.Value = i
wait()
end
end
end
year.Value += 1
end