Help with Timer display

Hello!

I would like to know how I can make a timer that displays in Minutes and seconds! I am using a server script for the timer countdown and a local script in StarterGui for the timer to display.

I’ve been bothered by how the timer looks and I thought that I could make it into a more fancy timer, but I don’t know how I can do this.

Here is what the timer looks like now:

Screenshot_96

It works fine, there are no errors.

Here is the server script for the timer:

--// Settings
local roundLength = 120
local intermissionLength = 30

local Intermission = false
local RoundRunning = false
local tweenService = game:GetService("TweenService")
local RoundStarted = game.ReplicatedStorage.RoundStarted
local Status = game.ReplicatedStorage.Status
BigCube = game.ServerStorage.BigCubeFolder:GetChildren()

--// Animations
local tween = tweenService:Create(game.Lighting, TweenInfo.new(10), {ClockTime = 0, Brightness = 2} )
local tween2 = tweenService:Create(game.Lighting, TweenInfo.new(10), {ClockTime = 14.5, Brightness = 3})
local tweenCloud = tweenService:Create(game.Workspace.Terrain.Clouds, TweenInfo.new(5.5), {Cover = 0.65, Density = 0.55})
local tweenCloud2 = tweenService:Create(game.Workspace.Terrain.Clouds, TweenInfo.new(10), {Cover = 0.5, Density = 0.55})
local tweenAtmosphere = tweenService:Create(game.Lighting.Atmosphere, TweenInfo.new(15), {Density = 0.55, Offset = 0.8})
local tweenAtmosphere2 = tweenService:Create(game.Lighting.Atmosphere, TweenInfo.new(4.5), {Density = 0.2, Offset = 0})

local intermissionSound = script.IntermissionMusic:Clone()
local survivalSound = script.SurvivalMusic:Clone()

intermissionSound.Parent = workspace
survivalSound.Parent = workspace

local function RunRound()
	Intermission = true
	intermissionSound:Play()
	while wait() do
		for i = intermissionLength, 1, -1 do
			RoundStarted.Value = false
			wait(1)
			Status.Value = i
		end
		tween:Play()
		tweenCloud:Play()
		tweenAtmosphere:Play()
		Intermission = false
		intermissionSound:Stop()

		local chosen = BigCube[math.random(1, #BigCube)]:Clone()
		chosen.Parent = workspace

		RoundRunning = true
		survivalSound:Play()
		Status.Value = "The "..chosen.Name.." is here! Survive!"
		for i = roundLength, 1, -1 do
			RoundStarted.Value = true
			wait(1)
			Status.Value = i
		end
		RoundRunning = false
		if RoundRunning == false then
			tween2:Play()
			tweenCloud2:Play()
			tweenAtmosphere2:Play()
			survivalSound:Stop()
			Status.Value = "The "..chosen.Name.." is gone for now..."
			intermissionSound:Play()
		else
			RoundRunning = true
		end
		wait(1)
		chosen:Destroy()
	end
end

spawn(RunRound)

Here is the local script:

function Refresh()

script.Parent.TimerDisplay.Text = game.ReplicatedStorage.Status.Value

end

Refresh()

game.ReplicatedStorage.Status.Changed:Connect(Refresh)

I have a feeling I would need to work on both of these script, but I don’t know what I can do.

How can I do this?

This script converts into Minutes and Seconds.

local function Minutes(Seconds)
	return string.format("%02i:%02i", Seconds/60%60, Seconds%60)
end

for i = 300, 0, -1 do
       print(Minutes(i))
       wait(1)
end

It kind of worked, but it won’t countdown now, here is what I did

**local function Minutes(Seconds)**
**	return string.format("%02i:%02i", 0/60%60, 0%60)**
**end**

**for i = 120, 0, -1 do**
**	Status.Value = (Minutes(i))**
**	wait(1)**
**end**

local function RunRound()
	Intermission = true
	intermissionSound:Play()
	while wait() do
		for i = intermissionLength, 1, -1 do
			RoundStarted.Value = false
			wait(1)
			Status.Value = i
		end
		tween:Play()
		tweenCloud:Play()
		tweenAtmosphere:Play()
		Intermission = false
		intermissionSound:Stop()

		local chosen = BigCube[math.random(1, #BigCube)]:Clone()
		chosen.Parent = workspace

		RoundRunning = true
		survivalSound:Play()
		Status.Value = "The "..chosen.Name.." is here! Survive!"
		for i = roundLength, 1, -1 do
			RoundStarted.Value = true
			wait(1)
			Status.Value = i
		end
		RoundRunning = false
		if RoundRunning == false then
			tween2:Play()
			tweenCloud2:Play()
			tweenAtmosphere2:Play()
			survivalSound:Stop()
			Status.Value = "The "..chosen.Name.." is gone for now..."
			intermissionSound:Play()
		else
			RoundRunning = true
		end
		wait(1)
		chosen:Destroy()
	end
end

**Minutes(120)**

So the first and last line is the Minutes function, as I said the timer did display in minutes and seconds, but it wouldn’t countdown

You don’t have to change the server script at all—this is purely a display issue. Just use @lilmazen1234’s function when setting the Text of your timer on the client.

Edit: also @lilmazen1234 typo on your parameter name should be s

I tried it in the local script, it works! But how can I match it up with the Intermission Length and the Round Length? It also prints out the time in the output, I want it to display it on the gui.

Intermission is 30 seconds and the Round is 120 (2 Minutes), would I have to make the same variable but in the local script?

Here is what my script looks like now:

function Refresh()

script.Parent.TimerDisplay.Text = game.ReplicatedStorage.Status.Value

end

local function Minutes(Seconds)

return string.format("%02i:%02i", Seconds/60%60, Seconds%60)

end

for i = 120, 0, -1 do

print(Minutes(i))

wait(1)

end

Refresh()

game.ReplicatedStorage.Status.Changed:Connect(Refresh)

game.ReplicatedStorage.Status.Changed:Connect(Minutes(120))

It prints it out but I don’t know how i can match it up with the server and how I can display it

local function Minutes(s)
  return string.format("%02i:%02i", s/60%60, s%60)
end

function Refresh()
  script.Parent.TimerDisplay.Text = Minutes(game.ReplicatedStorage.Status.Value)
end

Refresh()

game.ReplicatedStorage.Status.Changed:Connect(Refresh)

The for loop stuff was just them giving you an example of how to use it.

If this answers your question you should mark @lilmazen1234’s post as the answer

I have tried the script, I have gotten some errors.

Here are all of them:

Players.houston829.PlayerGui.RoundGui.TextChange:2: attempt to perform arithmetic (div) on string and number

Script ‘Players.houston829.PlayerGui.RoundGui.TextChange’, Line 2 - function Minutes

Script ‘Players.houston829.PlayerGui.RoundGui.TextChange’, Line 6 - function Refresh

Script ‘Players.houston829.PlayerGui.RoundGui.TextChange’, Line 9

Oh I’m sorry, I thought this was a NumberValue dedicated to the timer seconds only. I see now that it’s a general text status.

In that case, I take it back; your local script should be the same as you originally posted. Copy the Minutes function to your server script and wherever it says

Status.Value = i

Change it to

Status.Value = Minutes(i)
full script

--// Settings
local roundLength = 120
local intermissionLength = 30

local Intermission = false
local RoundRunning = false
local tweenService = game:GetService("TweenService")
local RoundStarted = game.ReplicatedStorage.RoundStarted
local Status = game.ReplicatedStorage.Status
BigCube = game.ServerStorage.BigCubeFolder:GetChildren()

--// Animations
local tween = tweenService:Create(game.Lighting, TweenInfo.new(10), {ClockTime = 0, Brightness = 2} )
local tween2 = tweenService:Create(game.Lighting, TweenInfo.new(10), {ClockTime = 14.5, Brightness = 3})
local tweenCloud = tweenService:Create(game.Workspace.Terrain.Clouds, TweenInfo.new(5.5), {Cover = 0.65, Density = 0.55})
local tweenCloud2 = tweenService:Create(game.Workspace.Terrain.Clouds, TweenInfo.new(10), {Cover = 0.5, Density = 0.55})
local tweenAtmosphere = tweenService:Create(game.Lighting.Atmosphere, TweenInfo.new(15), {Density = 0.55, Offset = 0.8})
local tweenAtmosphere2 = tweenService:Create(game.Lighting.Atmosphere, TweenInfo.new(4.5), {Density = 0.2, Offset = 0})

local intermissionSound = script.IntermissionMusic:Clone()
local survivalSound = script.SurvivalMusic:Clone()

intermissionSound.Parent = workspace
survivalSound.Parent = workspace

local function Minutes(s)
  return string.format("%02i:%02i", s/60%60, s%60)
end

local function RunRound()
	Intermission = true
	intermissionSound:Play()
	while wait() do
		for i = intermissionLength, 1, -1 do
			RoundStarted.Value = false
			wait(1)
			Status.Value = Minutes(i)
		end
		tween:Play()
		tweenCloud:Play()
		tweenAtmosphere:Play()
		Intermission = false
		intermissionSound:Stop()

		local chosen = BigCube[math.random(1, #BigCube)]:Clone()
		chosen.Parent = workspace

		RoundRunning = true
		survivalSound:Play()
		Status.Value = "The "..chosen.Name.." is here! Survive!"
		for i = roundLength, 1, -1 do
			RoundStarted.Value = true
			wait(1)
			Status.Value = Minutes(i)
		end
		RoundRunning = false
		if RoundRunning == false then
			tween2:Play()
			tweenCloud2:Play()
			tweenAtmosphere2:Play()
			survivalSound:Stop()
			Status.Value = "The "..chosen.Name.." is gone for now..."
			intermissionSound:Play()
		else
			RoundRunning = true
		end
		wait(1)
		chosen:Destroy()
	end
end

spawn(RunRound)
2 Likes

Thank you for helping! It works now, I’m sorry I did not see that at forst, I’m pretty new to scripting but I’m improving a lot!

1 Like