Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do i turn Intermission Value into minutes and secounds instead of just secounds?

So. I need some script that can turn this secounds to minutes and secounds intead of just secounds but i didint know how to make that so well, i am asking you guys now. so hope someone of you can help me turn this secounds into secounds and minutes like this for example (3:58) -- (3:08) -- (1:01) -- (15)

Here is the current script.

	function mss(t) -- Time in seconds
  		return string.format(
    	"%.1d:%.2d", -- Format. Number with minimum 1 digit, number with minimum 2 digits
    	t/60, -- Minutes
    	t%60 -- Seconds
  	)
	end

local Time = 300
local GameOverWait = 5 -- how long the GameOver text is on the screen.

while true do
		for i = Time,0,-1 do
		script.Parent.Times.Value = Time..i
		script.Parent.TimeLeft.Text = mss(Time)
		wait(1)
		end
		if script.Parent.Times.Value == 3000 then -- if local Time = 4 then add a 0 to the number.
			script.Parent.Parent.GameOver.Visible = true
			wait(GameOverWait)
			script.Parent.Parent.GameOver.Visible = false
		end
end	

1 comment

0

mss(i)

3 answers

✓ Accepted answer

Spelling errors:

Secounds = Seconds Didint = Didn't


The answer to your problem would be:

function digitalFormat(secs)
	local s = 0
	local m = 0
	
	-- you could do this:

	while s > 60 do
		s = s - 60 --takes 60 away from the seconds, eventually ending with the remaining seconds
		m = m + 1 -- adds one to the minutes
	end
	
	-- or this:

	m = math.floor(secs/60) -- math.floor rounds down to the nearest integer
	s = secs - (m*60) -- takes away however many seconds are in the minutes from the original seconds, leaving the original
	
	return m.. ":" ..s
end

print("Time Left: " ..digitalFormat(643)) -- prints 'Time Left: 10:43'

Alternately, you could just use PureConcept's answer and incorporate it into my code :P

So simply change Line 11 of your code to this (having defined the function earlier in your code):

script.Parent.TimeLeft.Text = "Time Left: " ..digitalFormat(i)

Hope I helped!

~TDP

2 comments

0

It gives me a nil value error on that script.Parent.TimeLeft.Text = "Time Left: " ..digitalFormat(i)

0

Delete one of the options, that is what is causing the error. Make sure 's' has a value of 'sec' if you chose the while loop option.

string.format

All of the other answers are nice, but there is a proper way to do this, which is to format a string in the style you want.

local function mss(t) -- Time in seconds
  return string.format(
    "%.1d:%.2d", -- Format. Number with minimum 1 digit, number with minimum 2 digits
    t/60, -- Minutes
    t%60 -- Seconds
  )
end

17 comments

0

Don't forgot to make use math.floor to make minutes an integer :P

0

Don't need to. It's automatically cast to an integer.

0

Where in my script can i put your script to get it to work and get it to print the seconds?

0

How? Is it because of the string patterns in format?

0

no, i mean like. how do i get that script to work with my script? so it will show that in my intermission text? i dont know where to put your script

0

Thing.Text = mss(yourTimeInSeconds)

0

Also it automatically casts to an integer if you use %d or %i

0

When i put that script into my script then the mss get a blue line under Thing.Text = mss(yourTimeInSeconds)

0

Where do you get the blue line? Copy-pasting requires a brain too.

0

well, i got a brain. The mss gets a blue line the mss in Thing.Text = mss(yourTimeInSeconds)

0

That's because you need to copy-paste my code into the top of your script? Mousing over the blue line does tell you the issue...

0

Thank you, But hmm how do i get it to count down then if i am using that cus it aint counting down anymore.

0

Uh, you put it in the right place? It's not difficult.

0

I put your script just below the While true do loop

0

It just stays on the 5:00 value it dosent count down to 0:00 why? i did put your script on the top of the while true do loop so can't see why it ain't working

0

Why is this so hard to understand? You set the text to mss(time) and you copy-paste my code at the top of your script.

0

Yea, But it dosent count down. If you check my script now then you see how i did it.

local time = 100
local minutes = string.format(".f", math.floor(time/60))
local seconds = string.format(".f", math.floor(time - minutes *60));

print(minutes .. ":" .. seconds)

2 comments

0

Fixed af now

0

got killed off of the flag

This discussion is preserved as it was. New answers, comments, and votes are closed.