Timer that counts upwards instead of counting downwards

Hello Developers, Aymoc here.

I’ve been working on my game recently and I wanted to make a Timer, with a twist to it.
I wanted to make the timer Tick or count up, so fx. 00:00:00 then 00:00:01
Instead of, 00:00:01 then 00:00:00, and further beyond.
The problem is that I’m not an experienced scripter.
I don’t know how to make this happen and it’s one of the most important features in my game to be made.

If you know how to make it work, and want to help me out then you are free to say something in the replies.

Edit: Problem Solved!

1 Like

You could do something like this. This will just print out but you could also use this for a text label.

local Maxseconds = 5000

for i = 1, Maxseconds,1 do
       wait(1)
       local minutes = math.floor(i/60)
       local hours = math.floor(minutes/60)
       local seconds = i - (minutes * 60)
       minutes -= hours * 60
       print(hours..":"..minutes..":"..seconds)
end
2 Likes

Alright, I’ll hop onto studio and try to do something with it. Thanks for the help man!

1 Like

Okay cool. Works perfectly fine. Do you know how i can insert it into a text label?

Put this script as a child of the text label.

local Maxseconds = 5000

local TextLabel = script.Parent

for i = 1, Maxseconds,1 do
       wait(1)
       local minutes = math.floor(i/60)
       local hours = math.floor(minutes/60)
       local seconds = i - (minutes * 60)
       minutes -= hours * 60
       TextLabel.Text = hours..":"..minutes..":"..seconds
end
1 Like

Works Very well. Now here is the part that I’ve wanted to make mainly,
There is a timer that starts when the server starts running. When you touch a specific part it resets back to 0 Do you know how to make that? You do not have to respond if you don’t want to this is just a question.

Put a bool value in replicated storage and name it “Touched”. Then do this for the local script:

local Maxseconds = 9999

local TextLabel = script.Parent

local BoolVal = game.ReplicatedStorage:WaitForChild("Touched")

while true do
    for i = 1, Maxseconds,1 do
           if BoolVal.Value == true then break end
           wait(1)
           local minutes = math.floor(i/60)
           local hours = math.floor(minutes/60)
           local seconds = i - (minutes * 60)
           minutes -= hours * 60
           TextLabel.Text = hours..":"..minutes..":"..seconds
     end
     repeat wait() until BoolVal.Value == false
end

Then put this as a server script, make it a child of the part that they have to touch

local db = false
script.Parent.Touched:Connect(function(hit)
      if hit.Parent:FindFirstChild("Humanoid") and db == false then
            db = true
           game.ReplicatedStorage.Touched.Value = true
           wait(3)
            db = false
           game.ReplicatedStorage.Touched.Value = false
      end
end)
1 Like

Very Good! Worked perfectly fine, I’ll tweak it myself a little but thanks for the help!

1 Like

Do you know how to make the timer like this 00:00:00? Because the timer right now is like this.
image

1 Like

I don’t know if this will work, if it doesn’t then I can come up with another solution.

local Maxseconds = 9999

local TextLabel = script.Parent

local BoolVal = game.ReplicatedStorage:WaitForChild("Touched")

while true do
    for i = 1, Maxseconds,1 do
           if BoolVal.Value == true then break end
           wait(1)
           local minutes = math.floor(i/60)
           local hours = math.floor(minutes/60)
           local seconds = i - (minutes * 60)
           minutes -= hours * 60
           minutes, hours, seconds = tostring(minutes), tostring(hours), tostring(seconds)
           if string.len(minutes) < 2 then minutes = "0"..minutes end
           if string.len(hours) < 2 then minutes = "0"..hours end
           if string.len(seconds) < 2 then minutes = "0"..seconds end
           TextLabel.Text = hours..":"..minutes..":"..seconds
     end
     repeat wait() until BoolVal.Value == false
end

Where do I put the script? Is it in the text label or in the part script?

The script inside of the text label.

Now it does this.
image

But after it becomes double digits then it formats itself correctly
image
Strange…

Yeah, I’ll take a look and get back to you. Can you add a print that prints the minutes, seconds, and hours variables and tell me what it says?

Also, it resets itself after 1 minute.

I have class right now but I can get back to you in about 30 minutes.

Alright, Also noticed that if i reset my character it resets the timer aswell.

Yeah, and if a player joins their timer will start at 1 second. When I get back I can fix all of that.

Cool! Let’s see if i can solve it myself that i doubt i can. :+1: