I'll pay 100 robux to the solution!

Put the long script in a serverscript, it will create the folders in the player for you when the game starts.
Thats all you need to do.
To add it to a GUI just do what I said before in a localscript that is in the GUI’s text label.

1 Like

Don’t make separate values. Just make a seconds value and use @SomeFedoraGuy’s method.

1 Like

This is the code for the localscript inside of the TextLabel:

local player = game.Players.LocalPlayer
local totalTime = player.Time.TotalTime
local textLabel = script.Parent

local RunService = game:GetService("RunService")
local counter = 0
RunService.Heartbeat:Connect(function(step)
	counter = counter + step
	if counter >= 1 then
		counter = counter - 1
		textLabel.Text = totalTime.Value
	end
end)

1 Like

To reset it when the player dies just reset all the values to nil

1 Like

Can you look at my local script at the very top of the thread? I kinda wanted to keep the milliseconds and stuff but I just wanted my timer to display as “1.00.00” for example and not “60.00”

1 Like

sorry I was using minutes and seconds. mb about the 60.00, I set it to > 60 not > 59
edit: replace all the 60s with 59

I don’t know how to write it out brother. I don’t know where any of that goes. I don’t know if I should delete that whole script for it or just add it in somewhere. I’m new to scripting and deving in general. I wish there was an in-depth video tutorial on how to do this so yall wouldn’t have to waste your time helping me but unfortunately nothing’s rang a bell for me yet.

so replace every 60 in sight with a 59 correct? even the one with the percentage after em

1 Like

All you need is a serverscript with this:

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%59)/59
	Seconds = Seconds - Minutes*59
	local Hours = (Minutes - Minutes%59)/59
	Minutes = Minutes - Hours*59

	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)

and a screen gui, with a frame, with a text label, that has a local script with this:

local player = game.Players.LocalPlayer
local totalTime = player.Time.TotalTime
local textLabel = script.Parent

local RunService = game:GetService("RunService")
local counter = 0
RunService.Heartbeat:Connect(function(step)
	counter = counter + step
	if counter >= 1 then
		counter = counter - 1
		textLabel.Text = totalTime.Value
	end
end)

So I never needed that long script I typed out at the beginning of the thread this whole time?

1 Like

No, all you need is my 2 scripts that I sent above

Also since it says “timeFolder” where do I need to add a folder? Do I add it in the workspace and if so what do I put in the folder?

The script will add the folder for you. There is no need to add it in yourself.

Alright Im testing the game! Gimme one sec

1 Like

This is a video of what it should look like (except the GUI)


Note: I made it an mp4

1 Like
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: " .. formatTime(currentTime) .. "\nPersonal Best: " .. formatTime(personalBest.Value)
personalBest.Changed:Connect(function()
    textLabel.Text = "Timer: " .. formatTime(currentTime) .. "\nPersonal Best: " .. formatTime(personalBest.Value)
end)

function formatTime(timeInSeconds)
    local minutes = math.floor(timeInSeconds / 60)
    local seconds = timeInSeconds % 60
    local milliseconds = (timeInSeconds % 1) * 1000

    return string.format("%02d:%02d.%03d", minutes, seconds, milliseconds)
end

function onStartTouched(hit)
    timerStopped = false
    startTime = tick()
    currentTime = 0
    Runservice.RenderStepped:Connect(function()
        if not timerStopped then
            currentTime = tick() - startTime
            textLabel.Text = "Timer: " .. formatTime(currentTime) .. "\nPersonal Best: " .. formatTime(personalBest.Value)
        end
    })
end
2 Likes

Its been and hour and a half, so Im going to head out now. I might see if I can polish my script a bit more and post it in #resources:community-resources.

I just saw @SilentMutiny’s post, maybe use that instead as it uses milliseconds.

1 Like

Yo send a link of one of your gamepasses for 100 robux ima buy it because you helped

Hey it said your script had a few errors but I fixed it! I gotta find out where to add my start and end blocks though so they can stop and start the timer. Then ima test the script

1 Like

Its fine. I learnt something new this so that is enough payment for me.

1 Like