How can I detect everytime the ClockTime passes 24?

So what I am trying to do is detect every time my ClockTime passes 24 to make day counter.

So far my attempts haven’t worked. Heres what I have tried so far:

function DayCounter()
	
	local Day = 1
	while true do
		wait(2)
		
		if game.Lighting:GetMinutesAfterMidnight() > 0 * 60 then
			Day = Day + 1
			print(Day)
		end
	end
end

But that just makes it so every 2 seconds it counts the day but what I want is to be so every time it passes 24 on the ClockTime it counts as a day.

1 Like

Make it so every amount of time a variable called counter goes up. Make it so lets just say your day goes for 10 mins, at the end of 10 mins the variable leads up to 24. Make it so every 2.4 mins counter goes up, so then after 10 mins it equals 24.
then do this:

if counter >= 24 then
Day = Day +1
counter = 0
end
end

Even though your script worked I’m not going to give your solution because my one that I just figured out works as well but it’s simpler.
Here’s my new one:

function DayCounter()
	while true do
		if game.Lighting:GetMinutesAfterMidnight() == 0 then
			Day = Day + 1
			if Day == 1 then
				DayName = "Monday"
			end
			if Day == 2 then
				DayName = "Tuesday"
			end
			if Day == 3 then
				DayName = "Wednesday"
			end
			if Day == 4 then
				DayName = "Thursday"
			end
			if Day == 5 then
				DayName = "Friday"
			end
			if Day == 6 then
				DayName = "Saturday"
			end
			if Day == 7 then
				DayName = "Sunday"
			end
			
			if Day >= 8 then
				Day = 1
			end
		end
	end
end

are you sure?
you can do it in a lot less lines like this:

local weekdays = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}
local currentDay = 0

--add a day to days if the time is 0
game.Lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
	if game.Lighting.ClockTime == 0 then
		currentDay = currentDay == 7 and 1 or currentDay + 1
		print(weekdays[currentDay]) --print out the current weekday
	end
end)

also, 60 * 0 is 0 so you might want to say game.Lighting:GetMinutesAfterMidnight() == 0

7 Likes

Surely wherever you cause the clock time to change you can use the same script to know for certain when you pass a day?

It seems strange to change it in one script and listen to it in another if they could both be one script.

@royaltoe’s script is way simpler and should be your choice :slight_smile: