How to attempt a week system

Trying to create a day night cycle that loops through a week (Monday-Sunday)

So far got the day/night cycle up fine

local Lighting = game:GetService('Lighting')

local Morning, Night, Speed = 6 * 60, 18 * 60, 0.05

local Day = 'Mon'

local Days = {
	'Mon', 'Tues', 'Wed', 'Thur', 'Fri', 'Sat', 'Sun'
}

while wait(0.1) do
	Lighting:SetMinutesAfterMidnight(Lighting:GetMinutesAfterMidnight() + Speed)
end

And I’ve obviously got the Day, as well as all the shortened version of the days in a table. So my thought process was when it hit midnight, change the day to the next day in the Days table, so like

if Lighting:GetMinutesAfterMidnight() == 0 then
	Day = Days[Day + 1]
end

I knew this would error out, but I’m not sure how to simply just get the next spot on the table?

2 Likes

I’d recommend Day = IndexNumber instead of the actual string. As what you were trying to do with
Day = Days[Day + 1]
you were trying to add a number to a string.
So I’d do something like
Day = Day + 1
DayName = Days[Day]

3 Likes
if Lighting:GetMinutesAfterMidnight() == 0 then
	Day = Days[Day + 1]
	print(Day)
end

Ended up working for 1 night (printed Tues) but the next night got this
[attempt to perform arithmetic on local ‘Day’ (a string value)]
nvm hold on, Im slow XDDDD

1 Like

Yeah, just stop it from indexing from the Days table and it will be fine.

1 Like