I'll pay 100 robux to the solution!

Anybody mind editing/rewriting my local script so that it shows my timer as minutes and seconds? I want it to show stuff like “1.00.00 and 1.05.00” not “60.00, 65.00” It’s for my obby and the timer works perfectly fine but I just want it to display regular stopwatch time. I’ve lost sanity and sleep over wrestling with this one script, i’ve tried everything even correcting the lines people in my other thread said to do but nothing works. Also I apologize about my grammar i’m just tired man. Script below:

local timerStopped = false
local Runservice = game:GetService("RunService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local personalBest = player:WaitForChild("PersonalBest") or math.huge
local replicatedStorage = game:GetService("ReplicatedStorage")

local textLabel = script.Parent
textLabel.Text = "Timer: " .. string.format("%.3f", currentTime) .. "\nPersonal Best: " .. string.format("%.3f", personalBest.Value)
personalBest.Changed:Connect(function()
	textLabel.Text = "Timer: " .. string.format("%.3f", currentTime) .. "\nPersonal Best: " .. string.format("%.3f", personalBest.Value)
end)

function onStartTouched(hit)
	timerStopped = false
	startTime = tick()
	currentTime = 0
	Runservice.RenderStepped:Connect(function()
		if not timerStopped then
			currentTime = tick() - startTime
			textLabel.Text = "Timer: " .. string.format("%.3f", currentTime) .. "\nPersonal Best: " .. string.format("%.3f", personalBest.Value)
		end
	end)
end

function onEndTouched(hit)
	if not timerStopped then
		timerStopped = true
		if currentTime > 0 and currentTime < personalBest.Value then
			personalBest.Value = currentTime
			replicatedStorage.BestTime:FireServer(currentTime)
		end
		textLabel.Text = "Timer: " .. string.format("%.3f", currentTime) .. "\nPersonal Best: " .. string.format("%.3f", personalBest.Value)
	end
end

workspace:WaitForChild("StartTimer").Touched:Connect(onStartTouched)
workspace:WaitForChild("EndTimer").Touched:Connect(onEndTouched)
13 Likes

You could just add 1 to the seconds value every second (or millisecond). You could show it as something like

minutes.Value… “.”… seconds.Value

I have not tested this yet

3 Likes

Brother the thing is I have no idea where to put anything. Im burnt out from working on the game and I hope somebody could just rewrite the script how I described I wanted it. I’m new to deving and scripting and this has been giving me a headache from hell all week :sob:

2 Likes

I will hop on studio and see if I can get this to work.

2 Likes

Preciate you man, the timer works marvelously and so does the start and stop part but it’s just I want the seconds displayed as minutes as time goes on. I just wish everything after “59.00” changes to the “1.23.45” format because today somebody told me that they beat my game in “2900.000 seconds” I was like WHAT? :sob:

2 Likes

Are you looking for hours or milliseconds? Some math could be done.

local function convert(Seconds)
	local function format(Int)
		return string.format("%02i",Int)
	end
	local Minutes = (Seconds - Seconds%60)/60
	Seconds = Seconds - Minutes*60
	local Hours = (Minutes - Minutes%60)/60
	Minutes = Minutes - Hours*60

	return string.format("%s : %s : %s",format(Hours),format(Minutes),format(Seconds)) 
end
2 Likes

Im just looking for the timer to change to “1.00.00” when 60 seconds have passed on it. Right now it only shows “60,61,62…”

Here is what I have gotten done: (in a server script)

local players = game:GetService("Players")

players.PlayerAdded:Connect(function(player)
	local timeFolder = Instance.new("Folder")
	timeFolder.Name = "Time"
	timeFolder.Parent = player
	
	local seconds = Instance.new("NumberValue")
	seconds.Name = "Seconds"
	seconds.Value = 0
	seconds.Parent = timeFolder
	
	local minutes = Instance.new("NumberValue")
	minutes.Name = "Minutes"
	minutes.Value = 0
	minutes.Parent = timeFolder
end)

local RunService = game:GetService("RunService")
local counter = 0
RunService.Heartbeat:Connect(function(step)
	counter = counter + step
	if counter >= 1 then
		counter = counter - 1
		for i,v in pairs(game.Players:GetChildren()) do
			local seconds = v.Time.Seconds
			local minutes = v.Time.Minutes
			seconds.Value += 1
			print(v.Name.. " Has been playing for ".. minutes.Value.. " Minutes and ".. seconds.Value.. " Seconds")
			if seconds.Value > 61 then
				seconds.Value = 0
				minutes.Value += 1
			end
		end
	end
end)

Edit: all it does is counts seconds and minutes then prints it out to the output

1 Like

Doesn’t the convert function I sent work? You could re-code it a little to show milliseconds instead of hours and shift things to the left

2 Likes

My code seems to work so far, but is probably not the best way of doing it. You would be better of using @SomeFedoraGuy’s convert function.

2 Likes

I’m a beginner scripter and my brain would explode trying to recode it :sob:

I updated the code to use the convert function.

local players = game:GetService("Players")

players.PlayerAdded:Connect(function(player)
	local timeFolder = Instance.new("Folder")
	timeFolder.Name = "Time"
	timeFolder.Parent = player

	local seconds = Instance.new("NumberValue")
	seconds.Name = "Seconds"
	seconds.Value = 0
	seconds.Parent = timeFolder

	local minutes = Instance.new("NumberValue")
	minutes.Name = "Minutes"
	minutes.Value = 0
	minutes.Parent = timeFolder
end)

local function convert(Seconds)
	local function format(Int)
		return string.format("%02i",Int)
	end
	local Minutes = (Seconds - Seconds%60)/60
	Seconds = Seconds - Minutes*60
	local Hours = (Minutes - Minutes%60)/60
	Minutes = Minutes - Hours*60

	return string.format("%s : %s : %s",format(Hours),format(Minutes),format(Seconds)) 
end

local RunService = game:GetService("RunService")
local counter = 0
RunService.Heartbeat:Connect(function(step)
	counter = counter + step
	if counter >= 1 then
		counter = counter - 1
		for i,v in pairs(game.Players:GetChildren()) do
			local seconds = v.Time.Seconds
			seconds.Value += 1
			local timePlayed = convert(seconds.Value)
			print(timePlayed)
		end
	end
end)

this is the result:
image

Edit:
To get it to also print the players name, you can just add v.Name like this:

print(v.Name.. " Has Played For, ".. timePlayed)

image

1 Like

Yo do you think theres a parenting issue in the scripts or my workspace?


1 Like

Y’all see how the timer is?


I created a “totaltime” value to store the players current time in a string.

	local totalTime = Instance.new("StringValue")
	totalTime.Name = "TotalTime"
	totalTime.Value = 0
	totalTime.Parent = timeFolder

Then update it every time a second/ minute is added by putting this under the print

v.Time.TotalTime.Value = timePlayed

Edit: this is what the TotalTime Value will look like while the game is running:
image

1 Like

Wait where did “timeFolder” come from? Scripting even this timer is hell for me but you guys make it seem like a piece of cake

Here is the entire script:

local players = game:GetService("Players")

players.PlayerAdded:Connect(function(player)
	local timeFolder = Instance.new("Folder")
	timeFolder.Name = "Time"
	timeFolder.Parent = player

	local seconds = Instance.new("NumberValue")
	seconds.Name = "Seconds"
	seconds.Value = 0
	seconds.Parent = timeFolder

	local minutes = Instance.new("NumberValue")
	minutes.Name = "Minutes"
	minutes.Value = 0
	minutes.Parent = timeFolder
	
	local totalTime = Instance.new("StringValue")
	totalTime.Name = "TotalTime"
	totalTime.Value = 0
	totalTime.Parent = timeFolder
end)

local function convert(Seconds)
	local function format(Int)
		return string.format("%02i",Int)
	end
	local Minutes = (Seconds - Seconds%60)/60
	Seconds = Seconds - Minutes*60
	local Hours = (Minutes - Minutes%60)/60
	Minutes = Minutes - Hours*60

	return string.format("%s : %s : %s",format(Hours),format(Minutes),format(Seconds)) 
end

local RunService = game:GetService("RunService")
local counter = 0
RunService.Heartbeat:Connect(function(step)
	counter = counter + step
	if counter >= 1 then
		counter = counter - 1
		for i,v in pairs(game.Players:GetChildren()) do
			local seconds = v.Time.Seconds
			seconds.Value += 1
			local timePlayed = convert(seconds.Value)
			print(v.Name.. " Has Played For, ".. timePlayed)
			v.Time.TotalTime.Value = timePlayed
		end
	end
end)

In the localscript, change the timer text to

"Timer: ".. player.Time.TotalTime.Value

To get the player, in the localscript, you need to do

local player = game.Players.LocalPlayer
1 Like

The time folder was a folder I created to store all the Values (totaltime, seconds, minutes). It was made in this line here: (line 4)

	local timeFolder = Instance.new("Folder")
	timeFolder.Name = "Time"
	timeFolder.Parent = player

I then used it as the parent of all the other values:

	seconds.Parent = timeFolder
	minutes.Parent = timeFolder
    totalTime.Parent = timeFolder
1 Like

Alright I’ll make a serverscript for the first script! Also how if you scroll up to the script I had above in the primary post thing can you tell me what and where I need to edit stuff? I apologize if im asking for so much but Im just new to all this and its gonna make my brain explode soon

So do I have to make my own folder for it or?