Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

os.date stops working at xx:59?

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

2 comments

0

Define 'breaks'.

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

1 answer

✓ Accepted answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.