It looks like you're over-complicating things, and (possibly) using unnecessary chunks to get to that result:
A. I don't recommend using os.time, as it doesn't cover individual time-zones, and focuses on a particular one; I recommend using tick instead, as it'll cover individual time-zones, and is said to be more accurate.
B. Your code, as I've said b4, looks like you're over-complicating something simple, but you're used a lot of unnecessary measures.
C. You're code is messy & isn't tabbed correctly.
D. Your variables are confusing, and don't (necessarily) represent their purpose: what is tNums supposed to mean? What's it supposed to do? Same w/ vHours, vSeconds, vLocal, etc.
E. You're trying to put number values in along w/ string values, which could result in your code breaking; I recommend using tostring to counter this.
F. Your explanations aren't very clear, and what you're trying to do is very vague.
Now, onto the code, it's a jumble-fest of mathematical calculations that aren't necessary, at least from my point of view: you don't require that much code to get the hours, minutes, etc.
Let's start over:
First off, instead of doing like you do, we're going to use a function to aid us in getting the time & returning it:
function CalculateAndReturnTime()
end
Next, we'll set up a variable for the time:
function CalculateAndReturnTime()
local CurrentTime = tick()
end
Now that we have our time variable set up, we'll proceed to creating variables that represents their purpose, and the same w/ their names:
function CalculateAndReturnTime()
local CurrentTime = tick() % 86400
local CurrentHour = math.floor(CurrentTime / 3600)
local CurrentMinute = math.floor(((CurrentTime / 3600) - CurrentHour) * 60)
local CurrentSecond = CurrentTime / 3600
end
Now that we have our mathematical calculations, we want the function to be able to return the results, which can be accomplished w/ the return function:
function CalculateAndReturnTime()
local CurrentTime = tick() % 86400
local CurrentHour = math.floor(CurrentTime / 3600)
local CurrentMinute = math.floor(((CurrentTime / 3600) - CurrentHour) * 60)
local CurrentSecond = CurrentTime / 3600
return CurrentHour, CurrentMinute, CurrentSecond
end
But wait! If we were to use the code as is, then the time wont be correct, b/c it may look like 6:5:8! :O But this is a simple fix. :P We can use the if statement to check & see if the number is less than 10, and if so, apply a 0 to it, to get 06:05:08! (/O-O)/
function CalculateAndReturnTime()
local CurrentTime = tick() % 86400
local CurrentHour = math.floor(CurrentTime / 3600)
local CurrentMinute = math.floor(((CurrentTime / 3600) - CurrentHour) * 60)\
local CurrentSecond = CurrentTime / 3600
if CurrentHour < 10 then
CurrentHour = "0" .. tostring(CurrentHour)
end
if CurrentMinute < 10 then
CurrentMinute = "0" .. tostring(CurrentMinute)
end
if CurrentSecond < 10 then
CurrentSecond = "0" .. tostring(CurrentSecond)
end
return CurrentHour, CurrentMinute, CurrentSecond
end
Now, this is where I stop: I'm not going any further, as then I'll just be giving you the entire code, but this should be sufficient enough to help get you started. :)
Stuff touched on but didn't get into great detail
Os.time
Tick
Tostring
Functions
Return
If statements
Time-Zones
Hope this helped you in any way. :)
EDIT
B4 I begin, I want to apologize for misunderstanding your answer, and assuming your code was messy. ;-;
Now, onto what you want accomplish: a countdown to zero to represent the time until the next day. (OH IT'S THE FINAL COUNTDOWN- DOO-DOO-DO-DO-DO-DOO :P)
We could take the current time, and have it be set on a basis, similar to my original code, but we'll make changes:
local SecondsInADay = 60 * 60 * 24
Ok, now that we have the variable for how many seconds is in a day, we'll take my original code format, then have it set to be subtracted by how many seconds there're in a day:
function timeBeforeDayEnds()
local SecondsInADay = 60 * 60 * 24
local CurrentTime = tick() % 86400
local CurrentHour = math.floor((CurrentTime / 60 / 60))
local CurrentMinute = math.floor(((CurrentTime - CurrentHour) * 60))
local CurrentSecond = (CurrentTime % 60) / 60
local HoursBeforeDayEnds = ((SecondsInADay % 86400) / 60) - CurrentHour
local MinutesBeforeDayEnds = ((SecondsInADay % 86400) / 60 / 60) - CurrentMinute
local SecondsBeforeDayEnds = (((SecondsInADay % 86400) % 60) / 60)
return HoursBeforeDayEnds, MinutesBeforeDayEnds, SecondsBeforeDayEnds
end
Man, that was a lot of work tbh. /(ToT)\=3 I'm sorry, but I can't really get into detail about the subtraction & calculations; it's very, very complicated; but I'm 77% confident that when you use run code, it'll return the hours, minutes, and seconds before the day ends. :) If not, I apologize if it doesn't work, as I'm working off memory. ;-;
Now, I'm going to need some Tylenol, ugh, my brain... T-T
I hope this helped you in any way. :)
2 comments
I updated & edited my answer.
Updated my chats.