# yes i do know posts like this exist

because i am hilariously bad at math, i really need to make this topic

essentially, i’m trying to make a timer (random between 90 seconds and 180 seconds), then convert that into minutes (to display it on the player’s GUI) and countdown to zero

thing is, i uh, i’m doing horribly

i hate mathematics (i have no idea what i’m doing)

``````local seconds = math.random(90,180)
print("Seconds selected: " .. seconds)
local minutes = math.floor(seconds/60)
local timer = math.floor(seconds%60)

print(timer)
``````

^ this will do a silly ^

bumping because i’m still stupid ash

1. did you write % accidentally?
2. the seconds if are under 60 the minutes would be decimal

i wrote everything accidentally i have no idea what i’m doing

1 Like

I believe you forgot to print out the minutes as you only printed out timer which is your time in seconds might want to rename it for next time

1 Like

Perchance, are you looking for a way to convert seconds to a `x:xx` format?
For example, 90 becomes `1:30`?

1 Like

YESYESYES

this is exactly what i’m trying to do

minutes will still be floored down to a number without decimals, so for example:

if a number like 144 is chosen, it will be floored down to 120 (which is 2 minutes)

i want it to be 2:24

To convert seconds to x:xx format, you can use this function

``````local function convert(seconds)
local cseconds = seconds % 60

if cseconds < 10 then
-- We don't want stuff like 0:3 or 1:1. We want it like 0:03 and 1:01 right?
-- Let's add a 0 before the single digit number.
-- 3 becomes 03, 1 becomes 01
cseconds = "0"..cseconds
end

-- This is how many minutes
local cminutes = math.floor( seconds / 60 )

-- Returns x:xx
return cminutes..":"..cseconds
end

print(convert(90)) -- outputs 1:30

``````
1 Like

oh my god oh my god

i can’t thank you enough for this

this is literally everything i’ve ever wanted

you’re absolutely goated thanks!!!

2 Likes