Ad
Log in to vote
0

GUI Script for a clock using game.Lighting.TimeOfDay not working. How do i fix this?

Asked by 9 days ago
Edited 9 days ago
while true do
    if game.Lighting.TimeOfDay == "06:00:00" then
        script.Parent.Text = "6:00 am"
        script.Parent.Day.Visible = true
        script.Parent.Night.Visible = false
    end
    if game.Lighting.TimeOfDay == "07:00:00" then
        script.Parent.Text = "7:00 am"
    end
    if game.Lighting.TimeOfDay == "08:00:00" then
        script.Parent.Text = "8:00 am"
    end
    if game.Lighting.TimeOfDay == "09:00:00" then
        script.Parent.Text = "9:00 am"
    end
    if game.Lighting.TimeOfDay == "10:00:00" then
        script.Parent.Text = "10:00 am"
    end
    if game.Lighting.TimeOfDay == "11:00:00" then
        script.Parent.Text = "11:00 am"
    end
    if game.Lighting.TimeOfDay == "12:00:00" then
        script.Parent.Text = "12:00 pm"
    end
    if game.Lighting.TimeOfDay == "13:00:00" then
        script.Parent.Text = " 1:00 pm"
    end
    if game.Lighting.TimeOfDay == "14:00:00" then
        script.Parent.Text = "2:00 pm"
    end
    if game.Lighting.TimeOfDay == "15:00:00" then
        script.Parent.Text = "3:00 pm"
    end
    if game.Lighting.TimeOfDay == "16:00:00" then
        script.Parent.Text = "4:00 pm"
    end
    if game.Lighting.TimeOfDay == "17:00:00" then
        script.Parent.Text = "5:00 pm"
    end
    if game.Lighting.TimeOfDay == "18:00:00" then
        script.Parent.Text = "6:00 pm"
        script.Parent.Day.Visible = false
        script.Parent.Night.Visible = true
    end
    if game.Lighting.TimeOfDay == "19:00:00" then
        script.Parent.Text = "7:00 pm"
    end
    if game.Lighting.TimeOfDay == "20:00:00" then
        script.Parent.Text = "8:00 pm"
    end
    if game.Lighting.TimeOfDay == "21:00:00" then
        script.Parent.Text = "9:00 pm"
    end
    if game.Lighting.TimeOfDay == "22:00:00" then
        script.Parent.Text = "10:00 pm"
    end
    if game.Lighting.TimeOfDay == "23:00:00" then
        script.Parent.Text = "11:00 pm"
    end
    if game.Lighting.TimeOfDay == "24:00:00" then
        script.Parent.Text = "12:00 am"
    end
    if game.Lighting.TimeOfDay == "01:00:00" then
        script.Parent.Text = "1:00 am"
    end
    if game.Lighting.TimeOfDay == "02:00:00" then
        script.Parent.Text = "2:00 am"
    end
    if game.Lighting.TimeOfDay == "03:00:00" then
        script.Parent.Text = "3:00 am"
    end
    if game.Lighting.TimeOfDay == "04:00:00" then
        script.Parent.Text = "4:00 am"
    end
    if game.Lighting.TimeOfDay == "05:00:00" then
        script.Parent.Text = "5:00 am"
    end
    if workspace.TimeValues.MidnightNoon.Value == 2 then
        script.Parent.Block1.BackgroundColor3 = (0, 0, 0)
    end
    if workspace.TimeValues.MidnightNoon.Value == 1 then
        script.Parent.Block1.BackgroundColor3 = (0, 192, 250)
    end
    if workspace.TimeValues.MidnightNoon.Value == 0 then
        script.Parent.Block1.BackgroundColor3 = (255, 255, 255)
    end

end

Im using this script in a GUI so that when its a certain time in game it does the following *The parent, text changes *Image labels, "Day, Night" becomes visible/unvisible the second if statement is if a value i have that changes in the workspace is 0 then it changes the color of a a text block thats in the parent of the script

but when i play the game, it does nothing at all what am i doing wrong?

locations of all the objects :

--startergui
    --Clock (screen GUI)
        --TheTime(text box)
            --TheScript
            --Day (image label)
            --Night(image label)
            --Block1(text box)

Hi.

Looks like you're using an ad blocker.

That's fine...

No, it really is.

Just, I mean, we put a lot of work into this site, you know?

It would be really really appreciated if you would turn off your ad blocker for our website...

We tried really hard to make our ads as unobtrusive as possible.

If you really hate ads, would you consider a $2 donation via Patreon?

Here's the link.

We love you. We hope you love us too.

.

..

...

Now back to your regularly scheduled Scripting Helpers....

...

..

.

2 answers

Log in to vote
0
Answered by
RubenKan 944
9 days ago

The reason your code doesnt work is because you have a while true do loop with no wait() in it. This will freeze roblox studio.

Because i have nothing better to do, im just going to give you a more complicated, but shorter version of your script.

Its really early and I might miss type things.

To get the hour of the time we can do

    local hour = math.floor(game.Lighting:GetMinutesAfterMidnight()/24)

To get am or pm we can then check if its below 13

    local amorpm

    if hour < 13 then
        amorpm = "AM"
    else
        amorpm = "PM"
    end

We can then add a modules operator to the time (%)

This basicly devides (/) valueA by valueB and returns the remainder.

    local moduledTime = hour
    local text = moduledTime..":00"..amorpm

The full script would look like:

while true do
    wait(1)

    local hour = math.floor(game.Lighting:GetMinutesAfterMidnight()/24)
    local amorpm

    if hour < 13 then
        amorpm = "AM"
    else
        amorpm = "PM"
    end

    local moduledTime = hour
    local text = moduledTime..":00"..amorpm
end
Ad
Log in to vote
0
Answered by 6 days ago
while true do
    wait(1)

    local hour = math.floor(game.Lighting:GetMinutesAfterMidnight()/60)
    local amorpm

    if hour == 0 then
        hour = 12
    end
    if hour > 12 then
        amorpm = "PM"
        hour = hour - 12
    else
        amorpm = "AM"
    end


    local moduledTime = hour
    local text = moduledTime..":00 "..amorpm

    script.Parent.Text = text


end

had to so some tinkering to get it to work correctly... thanks for the help :D

Answer this question



Ad