Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Clock isn't working correctly?

Asked by 4 years ago
Edited 4 years ago

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

Log in to vote
0
Answered by
KDarren12 705 Donator Moderation Voter
4 years ago
Edited 4 years ago

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.

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) JoshGamingHQ1 43 — 4y
0
Do you have something named "Text" inside of a GUI? KDarren12 705 — 4y
0
In that case, you targetted it in "Workspace", not "Workspace.GUI_NAME" KDarren12 705 — 4y
0
Yeah its not working. It updates to 12 AM only when the game starts, and then it stops. JoshGamingHQ1 43 — 4y
View all comments (2 more)
0
Never mind I used another script, but I'll accept this so you get the reputation. JoshGamingHQ1 43 — 4y
0
Thanks. KDarren12 705 — 4y
Ad

Answer this question