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

Can someone look over my time gui script? (12 hour time loop)

Asked by
s_iara 94
4 years ago

See, I'm trying to make a time gui with a 12 hour loop. I'm using a textlabel for this and already have a day and night script. I've tried a bunch of different scripts. I feel like this would work, but obviously nothing is.. This is what I have so far.

while true do
 script.Parent.Text = string.sub(game.Lighting.TimeOfDay,1,5)
 wait()
if Lighting.TimeOfDay >= 13 then
        script.Parent.Text = Lighting.TimeOfDay - 12
    elseif Lighting.TimeOfDay <= 12 then
    script.Parent.Text = string.sub(game.Lighting.TimeOfDay,1,5)
    wait()
end

Help would very much be appreciated

1 answer

Log in to vote
2
Answered by
royaltoe 5144 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

Your script was erroring because TimeOfDay was a string and you were comparing it to a number. You either compare the numbers to ClockTime, (or TimeOfDay if you converted it to a number like steamg0d said.)

Also, you need to change the time which idk if you're doing somewhere else but added it here.

changeTimeIncrement = .1-- how often you want to change the in game clock time in seconds

while wait(changeTimeIncrement) do  

    --update time
    local hoursPassed = 0
    local minutesPassed = 10
    game.Lighting.ClockTime = game.Lighting.ClockTime  + hoursPassed + (minutesPassed / 60)

    --convert to 12 hr format
    if game.Lighting.ClockTime >= 13 then
        local hour = math.floor(game.Lighting.ClockTime) 
        local minutes = math.floor((game.Lighting.ClockTime-hour)*60 + 0.5)
        local timeString = nil

        if(minutes >= 10)then
            timeString = hour - 12 .. ":" .. minutes
        else
            timeString = hour - 12 .. ":" .. minutes .. "0"
        end
        script.Parent.Text = timeString

    elseif game.Lighting.ClockTime <= 12 then
        if(game.Lighting.ClockTime < 10)then
            script.Parent.Text  = (string.sub(game.Lighting.TimeOfDay,2,5))
        else
            script.Parent.Text = (string.sub(game.Lighting.TimeOfDay,1,5))
        end
    end
end


1
Actually he can use TimeOfDay and just convert the string to a number SteamG00B 1633 — 4y
1
thx made edit. royaltoe 5144 — 4y
0
Thank you so much! It works, but one tiny issue. Instead if 10s, I want it to go by ones, if possible. Thank you! s_iara 94 — 4y
1
sure. change minutesPassed to 1 instead of 10 and it'll make 10 minutes pass evey 0.1 seconds. if you want time to change slower, change changeTimeIncrement to a bigger number. royaltoe 5144 — 4y
0
I know I'm very late, but it still doesn't work properly. Let's say it's 7:00 p.m. It'd do 7:10, :20, :30, :40, etc all the way to 7:90. Then it'd go by 1s.  s_iara 94 — 4y
Ad

Answer this question