Further in-depth explanation: I have coded a 'GetTime' type code [Which I have asked how-to-do real life timing a while back] that which would be used to Manipulation the Lighting Service's TimeOfDay property, however, it keeps returning an error, and stopping total execution of the code.
I am confused why it keeps on error-ring, because, I thought I coded it correctly, and the Output keeps saying the same thing every time, saying 20:51:13.735 - bad lexical cast: source type value could not be interpreted as target 20:51:13.737 - Script 'ServerScriptService.Script', Line 19 20:51:13.738 - Stack End, however, I can not understand what it means by that. This is the code I am currently using;
function GetTime()
local hour = math.floor((tick()%86400)/60/60);
local min = math.floor(((tick()%86400)/60/60-hour)*60);
local secs = (tick()%86400)/60/60;
secs = tostring(secs); local pos = nil;
for i = 1, #secs do
if secs:sub(i,i) == "." then
pos = secs:sub(i+1,#secs)
break
end
end
if not pos then return end
if min < 10 then min = '0'..min end
return hour,min,pos
end
repeat
local Hour, Min, Secs = GetTime()
game.Lighting.TimeOfDay = tostring(Hour) ..':'.. tostring(Min) .. ':' .. tostring(Secs)
game:GetService("RunService").Heartbeat:wait()
until nil

7 comments
But, line 13 is supposed to add the extra zero, preventing '10:9:8' from occurring. Also, I didn't know you could do it like that [For the last code]. o_e
Oh, I missed that, whoops, let me look more into this. Found it.
I just switched line 8 from 'pos = secs:sub(i+1,#secs)' to 'pos = secs:sub(i+1,i+2)', and it is working now for some reason, why is this when the other one was [probably] the same?
Oh, I don't think you're computing
secsat all correctly, that's why.Hmm, so 'secs' has to be two [At Max] numbers for the 'TimeOfDay' property to accept it? o_e
It has to be a two digit number. But you are selecting something after the decimal point, which isn't right. The correct math is posted here, much simpler.
That makes a lot of sense, and shortens code a log better than I knew, thanks a lot man! :D Also, congrats on 1.5K+! :D