From this code below, the seconds stays the same and never goes back to 0.
How can we fix this?
From this code below, the seconds stays the same and never goes back to 0.
How can we fix this?
it’s kind of hard to copy and paste text from a picture
can you add a code block to your post?
function Func_GetCurrentTime(str)
local tim = workspace.DistributedGameTime
--Example: 50.385758823
local secs = math.floor(tim) --50 secs
local mins = math.floor(secs/60) --50/60 secs
local hours = math.floor(mins/60) --0/60 secs
local days = math.floor(hours/24) --0/24 secs
if str == false then
return secs,mins,hours,days
else
return days..":"..hours..":"..mins..":"..secs
end
end
Is this running in a LocalScript? That may be why it doesn’t work.
Also, I know I shouldn’t be judging other people’s coding style but, why are you using “workspace” instead of “game.Workspace”?
The problem is on line 5
local secs = math.flooor(tim)
You are directly setting the value of tim
to secs
. So, if tim
is, for example, 100 seconds, secs
would be set to 100
You should use the modulo operator for the secs
variable. It returns the remainder when two numbers are divided:
local secs = math.floor(tim) % 60
local mins = math.floor(tim / 60)
-- so on
So when tim
is 100, secs
would be set to 40 (100 divided by 60 = 1 remainder 40)
I did local Mins = math.floor(Time/60), the problem I’m running into is when the minutes get above 60 it will add an hour onto the clock but the minutes wont go back down to 0, so I’ll have a weird clock where it’ll be like 01:72:49 or something, with 72 being the minutes.