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 game.Players.PlayerAdded:Connect(function(plr) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = plr local cash = Instance.new("IntValue") cash.Name = "Gold" cash.Value = 50 cash.Parent = leaderstats 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
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. :)