Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Clock isn't working correctly?

So I'm trying to make a GUI that displays the time using the "GetMinutesAfterMidnight()" line. I have this, but it isn't working. I just get a script timeout.

local timeCheck = game.Lighting:GetMinutesAfterMidnight()

while true do
	if timeCheck < (1 * 60) then
		script.Parent.Text = "12 AM"
else
	if timeCheck < (2 * 60) and timeCheck > 59 then
		script.Parent.Text = "1 AM"
		end
	end
end
-- then I add extra of the above going from 12AM - 11PM

This might have something to do with the "else" tag, but I'm not sure.

1 answer

✓ Accepted answer

Just add a wait(). Your program is timing out because the "while true do" loop is running many times per second.

local timeCheck = game.Lighting:GetMinutesAfterMidnight()
	 
	while true do
wait() -- add a time if you chose
	    if timeCheck < (1 * 60) then
	        script.Parent.Text = "12 AM"
	else
	    if timeCheck < (2 * 60) and timeCheck > 59 then
        script.Parent.Text = "1 AM"
	        end
	    end
	end
	-- then I add extra of the above going from 12AM - 11PM

If this doesn't work, please tell me.

6 comments

0

The GUI isn't updating, and now I'm getting the error "Text is not a valid member of Workspace" (Nevermind it was another script causing that error)

0

Do you have something named "Text" inside of a GUI?

0

In that case, you targetted it in "Workspace", not "Workspace.GUI_NAME"

0

Yeah its not working. It updates to 12 AM only when the game starts, and then it stops.

0

Never mind I used another script, but I'll accept this so you get the reputation.

0

Thanks.

This discussion is preserved as it was. New answers, comments, and votes are closed.