I'm making a timer that converts seconds into hh:ss to show in a text box. I already have all the math correct, the one problem is that if the time is less then ten seconds (same with hours) it will show as h:s and if it is over it will show as h:sss.
All I need to do is make it so that there is always two digits before the decimal, no more no less. So basically like math.floor but in the other direction. How could I do this?
Heres the script if you need more context:
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local songprofile = game.Players.LocalPlayer.PlayerScripts:WaitForChild("SoundPlayer")
local timeElapsed = 0
RunService.Heartbeat:Connect(function(step)
if songprofile.Sound.Playing then
timeElapsed = timeElapsed + step
script.Parent.Text = math.floor(timeElapsed / 60) .. ":" .. math.floor(timeElapsed) .. " - " .. math.floor(songprofile.Sound.TimeLength / 60) .. ":" .. math.floor(songprofile.Sound.TimeLength) -- here --
end
end)
songprofile.Sound.DidLoop:Connect(function()
script.Parent.Text = "0:00 - " .. math.floor(songprofile.Sound.TimeLength / 60) .. ":" .. math.floor(songprofile.Sound.TimeLength) -- here --
end)
songprofile.Sound.Paused:Connect(function()
script.Parent.Text = math.floor(songprofile.Sound.TimePosition / 60) .. ":" .. math.floor(songprofile.Sound.TimePosition) .. " - " .. math.floor(songprofile.Sound.TimeLength / 60) .. ":" .. math.floor(songprofile.Sound.TimeLength) -- and here --
end)
Fixed it myself with
math.floor(timeElapsed / 60 - (math.floor(timeElapsed / 60) * 60))
