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

How come my time-code isn't working after the first loop?

Asked by 7 years ago
Edited 7 years ago

Today I tried creating a Time-GUI that which would tell the time - it is designed after my original Time-GUI - but it appears to only work after the first execution of when the repeat/ loop fired.

There's no Output, other than the prints I put in to check if it was firing correctly; to make clear on this, it's the Time that's not changing, not the loop itself, as both prints (there're 2) fire as the loop goes/ executes.

I have no clue, and have tried every method I could think of how to fix this/ figure out the problem; however, my efforts turned to failure, and I couldn't figure it out.

This is the Time-GUI's code:

local SettingsModule = require(script:WaitForChild('Settings'))
local timegui = script.Parent:WaitForChild('Time')
local ts = tostring
local AMorPM = 'AM'
local TimeDifference = SettingsModule.TimeType and 12 or 0 -- True or false value in the module.

function GetTime()
    local TimeType = SettingsModule.TimeType -- In the module, the default is tick, but can be changed to os.time.
    local Hour = math.floor((TimeType%86400)/60/60)
    local Mins = math.floor(((TimeType%86400)/60/60-Hour)*60)
    local Secs = math.floor(((TimeType%86400)%60/60)*60)

    if Hour > 11 then AMorPM = 'PM' else AMorPM = 'AM' end
    if Hour > 12 then Hour = Hour - TimeDifference end
    if Hour < 10 then Hour = '0' .. ts(Hour) end
    if Mins < 10 then Mins = '0' .. ts(Mins) end
    if Secs < 10 then Secs = '0' .. ts(Secs) end

    return ts(Hour) .. ':' .. ts(Mins) .. ':' .. ts(Secs) .. ' ' .. AMorPM -- Returns the time.
end -- I'm aware the code doesn't look very efficient, but I wanted to take a step back.


repeat -- Before the repeat, I tried a while loop, but repeat had the same problem as well.
    wait(1 / 15) -- I thought wait() was the problem, but in turn, there was no difference.
    print('Fire1') -- Fired
    timegui.Text = GetTime() -- Need I explain?
    print('Fire2') -- Fired
until nil

I simply just can't figure out what the problem is; it worked the first time, but isn't anymore for some reason. e-e

0
And the wait begins... TheeDeathCaster 2368 — 7y

Answer this question