Someone help me with this math problem in my script

someone help me with this math problem in my script
I am trying to transform a Falor (Seconds) in hours and minutes and make it a formed one like for example (00:00:00) more with this script I made it a bug that goes both for hours and minutes and seconds -30 to 30 (the range would be from 0 to 60) if you can help me … please ;-;

My Script

local DataStore = game:GetService("DataStoreService")
local DataBoard = DataStore:GetDataStore("DataBoard")
local DataPlayed = DataStore:GetDataStore("SecoundsPlayed".."1")	

game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder", player) leaderstats.Name = "leaderstats"
local SecoundsPlayed = Instance.new("IntValue", player) SecoundsPlayed.Name  = 
"SecoundsPlayed"
		
SecoundsPlayed.Value = DataPlayed:GetAsync(player.UserId) or 0

local debaunce = false

while true do
	SecoundsPlayed.Value = SecoundsPlayed.Value +1
	
local Hours = Instance.new("IntValue")
local Minutes = Instance.new("IntValue")
local Secounds = Instance.new("IntValue")
Hours.Value = SecoundsPlayed.Value/3600
Minutes.Value = (SecoundsPlayed.Value/60)-(60*Hours.Value)
Secounds.Value = (SecoundsPlayed.Value) - (60*Minutes.Value)

local TH = ""
local TM = ""
local TS = ""
	
	
	if Secounds.Value < 10 then	
	TS = "0"..Secounds.Value
	else
	TS  = Secounds.Value
	end

	if Minutes.Value < 10 then
	TM = "0"..Minutes.Value
	else
	TM  = Minutes.Value
	end
	
	if Hours.Value < 10 then
	TH = "0"..Hours.Value
	else
	TH  = Hours.Value
	end	
    print(TH..":"..TM..":"..TS)
	wait(1)
end
end)

Screenshot_17

Here’s the function I use for time formatting:

function formatTime(t)
	local sign = t < 0 and "-" or ""
	local s = math.floor(math.abs(t) + 0.5)
	local h = math.floor(s / 3600)
	s = s % 3600
	local m = math.floor(s / 60)
	s = s % 60
	local ret = sign..((h < 10) and ("0"..h) or h)
	ret = ret..":"..((m < 10) and ("0"..m) or m)
	ret = ret..":"..((s < 10) and ("0"..s) or s)
	return ret
end

print(formatTime(12987)) --> 03:36:27
print(formatTime(-265)) --> -00:04:25

First the total number of seconds is divided by the number of seconds in an hour to get the number of hours. Then take the remainder of that and divide by the number of seconds per minute to get the number of minutes. The remainder of that is the number of seconds. Then it’s just a matter of concatenating the numbers together.

Alternatively you can use patterns to format the return string. I wrote the above function before I knew about them.

local ret = sign..string.format("%02d:%02d:%02d", h, m, s)
4 Likes

thank you very much helped :smile: :smile: