Script timeout: exhausted allowed execution time

I have a script that detects when it becomes midnight and changes a textlabel to the current day, but it doesn’t work and the output shows

  23:35:10.362  Script timeout: exhausted allowed execution time  -  Client - LocalScript:4

I’ve tried looking this up and it didn’t seem like people had the same scenario as me. If anybody knows how to correct this error I would really appreciate it.
Here is my script if you are wondering.

local DayVal = script.Parent.Parent.Day.CurrentDay

while true do
	if game.Lighting:GetMinutesAfterMidnight() == 0 then
		DayVal.Value = DayVal.Value + 1
		local Val = DayVal.Value
		if Val == 1 then
			script.Parent.Text = "Monday"
		end
		if Val == 2 then
			script.Parent.Text = "Tuesday"
		end
		if Val == 3 then
			script.Parent.Text = "Wednesday"
		end
		if Val == 4 then
			script.Parent.Text = "Thursday"
		end
		if Val == 5 then
			script.Parent.Text = "Friday"
		end
		if Val == 6 then
			script.Parent.Text = "Saturday"
		end
		if Val == 7 then
			script.Parent.Text = "Sunday"
		end
		if DayVal.Value >= 8 then
			DayVal.Value = 1
		end
		
	end
end

You need to add some sort of wait() or it will exchaust.

1 Like
local DayVal = script.Parent.Parent.Day.CurrentDay

while wait() do
	if game.Lighting:GetMinutesAfterMidnight() == 0 then
		DayVal.Value = DayVal.Value + 1
		local Val = DayVal.Value
		if Val == 1 then
			script.Parent.Text = "Monday"
		end
		if Val == 2 then
			script.Parent.Text = "Tuesday"
		end
		if Val == 3 then
			script.Parent.Text = "Wednesday"
		end
		if Val == 4 then
			script.Parent.Text = "Thursday"
		end
		if Val == 5 then
			script.Parent.Text = "Friday"
		end
		if Val == 6 then
			script.Parent.Text = "Saturday"
		end
		if Val == 7 then
			script.Parent.Text = "Sunday"
		end
		if DayVal.Value >= 8 then
			DayVal.Value = 1
		end
		
	end
end
1 Like