How can I change the timer format from seconds to minutes?

I removed the remote event part because I don’t have a remote event for the script and I thought it would work

local roundlength = 100
local intermissionlength = 0
local InRound = game.ReplicatedStorage.InRound
local Status = game.ReplicatedStorage.Status
local Camera = workspace.CurrentCamera

function ConvertClock(Time)
	if Time ~= 1 or Time ~= 0 then
		local minutes = math.floor(Time / 60)
		local seconds = math.floor(Time % 60)

		return {minutes, seconds}
	else return Time end
end

function Timer(seconds)
	for i = seconds, 0, -1 do
		local minutes = math.floor(i/60)
		local sec = math.floor(i%60) -- Optional

		--return string.format("%02i:%02i", minutes, sec)
		string.format("%02i:%02i", minutes, sec)
	end	
end

local function Teleport(Location)
	if not workspace.Spawns:FindFirstChild(Location) then return end
	for _, player in pairs(game.Players:GetPlayers()) do
		local char = player.Character or player.CharacterAdded:wait()
		char.HumanoidRootPart.CFrame = workspace.Spawns[Location].CFrame
	end
end

InRound.Changed:Connect(function()
	if InRound.Value == false then 
		Teleport("LobbyTP")
	end
end)
local function roundTimer()
	while wait() do
		for i = intermissionlength, 0, -1 do
			InRound.Value = false
			wait(1)
			Status.Value = "TIME: ".. i ..""
		end
		for i = roundlength, 0, -1 do
			InRound.Value = true
			wait(1)
			Status.Value = "TIME: ".. i ..""
			if i <= 0 then
				Ended()
			end
		end
	end
end
spawn(roundTimer)
function Ended()
	for _, player in pairs(game.Players:GetPlayers()) do
		pcall(function()
			player.PlayerGui.EndGui.CameraHandler.Disabled = false
			task.delay(5,function()
				player.PlayerGui.EndGui.CameraHandler.Disabled = true
			end)
		end)
	end
	game.Workspace.Enemies:ClearAllChildren()
	game.Workspace.Pickups:ClearAllChildren()
end

So this is a server script correct?

Yes is a server script in server script service

I don’t think you can get the currentCamera in a server script, correct me if I’m wrong.

Actually it does work with currentCamera

1 Like

Can you send a screenshot of the error? Or just say what line did the error happen on.

in the .Text = tostring line

Sorry for the late reply but I don’t see where you the text has been changed?

Same here:

image

Also, here is the revised function:

function ConvertClock(Time)
	function ConvertClock(Time)
	local minutes = math.floor(Time / 60)
	local seconds = math.floor(Time % 60)
	
	if tostring(seconds):len() == 1 then
		seconds = tostring("0"..seconds)
	end
	
	return {tostring(minutes), tostring(seconds)}
end

for i = 1, 120 do
	local c = ConvertClock(i)
	print(c[1]..":"..c[2])
	task.wait(1)
end

So what you would do is this:

function Timer(seconds)
   for i = seconds, 0, -1 do
      local minutes = math.floor(i/60)
      textLabel.Text = string.format("%02i:00", minutes) -- String.Format simply just formats the string. You would still need to change the text so define where your textLabel is and edit the text.
   end	
end
1 Like

I have no idea how string.format works, so I just use the cave man method of using .. lol.

Yeah lol I found out recently and I find it to be much better, however I still don’t know what %02i means and all the other methods.

1 Like

The text is changed in a local script inside the timer gui text

Then can you send the local script?

Yeah so add that to your client script, I would still recommend using remoteEvents. I will have to go now, so any question may get a late reply.

1 Like
local status = game.ReplicatedStorage.Status
local Time = script.parent.Time

status.Changed:Connect(function()
	Time.Text = status.Value
end)
1 Like

Try this instead, also the status value has to be an int value, or an number value that has only whole numbers.

local status = game.ReplicatedStorage.Status
local Time = script.parent.Time

function ConvertClock(Time)
	local minutes = math.floor(Time / 60)
	local seconds = math.floor(Time % 60)

	if tostring(seconds):len() == 1 then
		seconds = tostring("0"..seconds)
	end

	return {tostring(minutes), tostring(seconds)}
end

status.Changed:Connect(function()
	local c = ConvertClock(status.Test)
	Time.Text = c[1]..":"..c[2]
end)

It is a string value. Does that count?

Also I check the properties of the status value and now it is back to how it was before. The function is not deleted

Just use tonumber on the c variable like so:

Also I recommend putting the ConvertClock function inside a module script so you can use for another thing later.

local status = game.ReplicatedStorage.Status
local Time = script.parent.Time

function ConvertClock(Time)
	local minutes = math.floor(Time / 60)
	local seconds = math.floor(Time % 60)

	if tostring(seconds):len() == 1 then
		seconds = tostring("0"..seconds)
	end

	return {tostring(minutes), tostring(seconds)}
end

status.Changed:Connect(function()
	local c = ConvertClock(tonumber(status.Test))
	Time.Text = c[1]..":"..c[2]
end)