0

# How To Transform Seconds Into Hours/Minutes/Seconds?

hey Devs I have been Working On A Daily Reward System And I Cant Transform the Seconds Into Hours/ Minutes / Seconds can you guys help me in it. my code is this

local Chest = game.Workspace.Chest

local Chest2 = game.Workspace.CHEST2

local Lower = Chest2.NameTag.Lowertext

local debounce = false

local drtime = 6*60*60

local dailyreward = 250

Lower.Text = dailyreward

local cash = Instance.new("IntValue")
cash.Name = "Gold"
cash.Value = 50

Chest.Touched:Connect(function()
if not debounce then
debounce = true
cash.Value = cash.Value + dailyreward
for i = drtime, 1, -1 do
Lower.Text = i
wait(1)
end
debounce = false
Lower.Text = dailyreward
end
end)
end) -- DONT MIND IT I KNOW ITS CRAPPY

0
it does doe works as i want it to work kidsteve923 80 — 10d
0
I don't understand what you want us to do Spjureeedd 363 — 10d
0
i Said I want the seconds to be in hours / minutes / seconds LIKE A TIMER on daily rewards kidsteve923 80 — 10d
0
Yes thank you, it really helped when you repeated the exact same thing. Do you wonder how many seconds there is in one minute and one hour or what exactly is it you want? Spjureeedd 363 — 10d

0
sifn 35
10 days ago

This takes math and I am not particularly good at math, so I searched your question through Google to see if it was already solved by someone else in the past - chances are it was, because this is actually a common question - and good news friend, it was!

Right, so the solution can be found in this DevForum post. Have a look if you can. To summarize, all you need to do is copy-paste two functions into your code:

function Format(Int)
return string.format("i", Int)
end

function convertToHMS(Seconds)
local Minutes = (Seconds - Seconds%60)/60
Seconds = Seconds - Minutes*60
local Hours = (Minutes - Minutes%60)/60
Minutes = Minutes - Hours*60

return Format(Hours)..":"..Format(Minutes)..":"..Format(Seconds)
end


The two above functions can be used to format any given amount of seconds into the h:m:s format you're looking for. Put them at the top of your script.

With that done, simply format the number of seconds remaining using the convertToHMS() function every time a second is subtracted. It would look like so:

for i = drtime, 1, -1 do
Lower.Text = convertToHMS(i)
wait(1)
end


Et voila. Your script now should count down from 21600 seconds, or 6 hours, in the appropriate format, making for the daily reward system you desire.

Be sure to mark my answer as the solution (with the green checkmark) if this works for you! If it doesn't work, let me know with a comment and I will see if there is something I missed. :)