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

How would I make the timer "minutes:seconds" instead of just seconds?

Here is the script that I'm working with:

ServerStorage = game:GetService("ServerStorage")
ReplicatedStorage = game:GetService("ReplicatedStorage")
Players = game:GetService("Players")

Maps = ServerStorage:WaitForChild('Maps'):GetChildren()
Status = ReplicatedStorage:WaitForChild('Status')

while true do
	
	local Countdown = 10 -- Intermission Time
	
	repeat wait(1)
		Countdown = Countdown - 1
		
		Status.Value = 'Intermission : '..Countdown
	until Countdown <= 0
	
	
	
	Status.Value = 'Choosing Map.'
	
	local ChosenMap = Maps[math.random(1, #Maps)]:Clone()
	local Spawns = ChosenMap:FindFirstChild('Spawns'):GetChildren()
	local RandomSpawn = Spawns[math.random(1, #Spawns)]
	
	wait(5) -- little pause, make this as long as you want
	
	ChosenMap.Parent = workspace
	Status.Value = 'Map chosen, teleporting players.'
	
	wait(2) -- little pause, make this as long as you want
	
	
	
	for _, Player in pairs(Players:GetChildren())do
		if Player.Character and Player.Character:FindFirstChild('Humanoid') then
			Player.Character.HumanoidRootPart.CFrame = RandomSpawn.CFrame
		end
	end
	
	Countdown = 3 -- Starting Round In, make this as long as you want
	
	repeat wait(1)
		Countdown = Countdown - 1
		
		Status.Value = ' Round Starts in : '..Countdown
	until Countdown <= 0
	
	Countdown = 10 -- Game Time.
	
	repeat wait(1)
		Countdown = Countdown - 1
		
		Status.Value = 'Time Left : '..Countdown
	until Countdown <= 0
	
	
	
	for _, Player in pairs(Players:GetChildren())do
		if Player.Character and Player.Character:FindFirstChild('Humanoid') then
			Player.Character.Humanoid:TakeDamage(2000)
		end
	end
	
	ChosenMap:Destroy()
	
	Status.Value = 'Round Ended, waiting for new game.'
	
	wait(4) -- little pause, make this as long as you want.
	
end
ServerStorage = game:GetService("ServerStorage")
ReplicatedStorage = game:GetService("ReplicatedStorage")
Players = game:GetService("Players")

1 answer

✓ Accepted answer

You can use the operator modulus (%) to get the remainder of a division problem. So, for example:

5 / 2 = 2.5

but with modulus:

5 % 2 = 1

So if you have a variable Countdown with the amount of seconds left, you can do Countdown % 60 in order to find the amount of seconds that do not fit in a minute. You can then subtract that from the total of countdown, and then divide by 60 in order to find the amount of minutes in Countdown.

function secondsToTimer(num)
	local sec = num % 60
	local min = (num - sec) / 60

	local str = ""
	
	if min <= 9 then
		str = str.."0"..min..":"
	else
		str = str..min..":"
	end

	if sec <= 9 then
		str = str.."0"..sec
	else
		str = str..sec
	end

	return str
end

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