Why is my clock script not working?

I have written a script that tells the IRL time and it is not working, here is the script:

local mainFrame = script.Parent:WaitForChild("MainFrame")
local timeLabel = mainFrame:WaitForChild("Time")

while wait() do
	local seconds = os.date("*t")["sec"]
	local minutes = os.date("*t")["min"]
	local hours = os.date("*t")["hours"]
	
	if tonumber(seconds) <= 9 then
		seconds = "0"..seconds
	end
	
	if tonumber(minutes) <= 9 then
		minutes = "0"..minutes
	end
	
	if tonumber(hours) <= 9 then
		hours = "0"..hours
	end
	
	timeLabel.Text = hours..":"..minutes..":"..seconds
end

Here is the error:

Players.potatocure.PlayerGui.TimeGui.LocalScript:17: attempt to compare nil <= number - Client - LocalScript:17

The problem would be this line. change it to “hour” not “hours”

local hours = os.date("*t")["hour"]
1 Like

Thank you, you’ve fixed it. Thanks for the reply :grinning_face_with_smiling_eyes:

With os.date("*t) that is UTC (BST/GMT), how do I make it CEST (UTC+1)?

You can not change the timezone, you would just need to add the time difference to the table. to do this, you just need something like this:

local mainFrame = script.Parent:WaitForChild("MainFrame")
local timeLabel = mainFrame:WaitForChild("Time")

while wait() do
	local cesttime = os.time() + 7200
	local seconds = os.date("*t", cesttime)["sec"]
	local minutes = os.date("*t", cesttime )["min"]
	local hours = os.date("*t", cesttime )["hours"]
	
	if tonumber(seconds) <= 9 then
		seconds = "0"..seconds
	end
	
	if tonumber(minutes) <= 9 then
		minutes = "0"..minutes
	end
	
	if tonumber(hours) <= 9 then
		hours = "0"..hours
	end
	
	timeLabel.Text = hours..":"..minutes..":"..seconds
end

Try the making the hours tonumber(variable os.date("*t")["hour"]) + 1