I got the minutes part of this timer im making but the minutes and seconds don’t work can anyone help?

Script:

I got the minutes part of this timer im making but the minutes and seconds don’t work can anyone help?

Script:

1 Like

Use `math.floor`

for all numbers. Also, please note that `tostring`

is unnecessary here.

Try this function:

```
function toHMS(seconds)
return string.format("%02i:%02i:%02i", seconds/60^2, seconds/60%60, seconds%60)
end
local time = toHMS(600)
```

5 Likes

What’s happening is you’re taking 6 (Hours) and dividing it into 60, and then dividing it by 60 again. This is why you’re getting those crazy decimals.

You’ll need to write a function that deconstructs the time into its components:

1) Divide the time by 3600 to get how many hours are left.

2) If step 1 results in a number that contains a decimal, multiply that decimal by 60 to get the minutes left in that hour.

3) If step 2 results in a number that contains a decimal, multiply that decimal by 60 to get the seconds left in that hour.

4) Math.floor these variables *after* doing the calculations so the numbers are nice and whole.

5) Profit???