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

os.date stops working at xx:59?

Asked by 5 years ago

Hello,

I have an os.date to display the out but it doesn't work after the clock shows xx:59. It completely breaks.

local hourFull = {"01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24"}
local minFull = {"01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45","46","47","48","49","50","51","52","53","54","55","56","57","58","59","60"}
local hourAfter
local minAfter

local hourAfter = hourFull[hour]
local minAfter = minFull[min]

local timeZone = 1 -- Change to 0 for GMT, 1 for BST

if timeZone == 1 then
    script.Parent.Screen.GateGui.Main.Off.Clock.Desc.Text = "Time in BST"
else
    script.Parent.Screen.GateGui.Main.Off.Clock.Desc.Text = "Time in GMT"
end

while true do
    hour = os.date("!*t")["hour"] + timeZone
    min = os.date("!*t")["min"] 
    wait()

    script.Parent.Screen.GateGui.Main.Off.Clock.Clock.Text = hourFull[hour]..":"..minFull[min]
    wait(1)
end

0
Define 'breaks'. climethestair 1663 — 5y
0
The TextLabel stops at xx:59, doesn't change, never changes again on that server. It works fine until then. No errors, nothing on output AvionicScript 65 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

This is just a guess, but maybe when it gets to 0 minutes it gets nil because there isn't an index of 0 in your array. In lua it starts at 1.

What you could do is have a function that converts 1 digit numbers like this...

function convertTwoDigits(num)
    if string.len(tostring(num)) <= 1 then
        return "0"..num
    end
    return num
end
Ad

Answer this question