How to make a timer for my game

Hello, I’m currently working on a game that basically you have to speedrun an obby and fight with other players, I want a stopwatch/timer to count how much did it took each player to finish the obby. I would be glad if somebody could help me.

1 Like

You can make a value, NumberValue, IntValue, etc. You can make a script where it’ll add 1 number every second, like this:

while true do
IntValue.Value = IntValue.Value + 1
wait(1)
end

I had the same issue as you my friend. I made a topic on this a while back and a person named @Hexcede helped me out with it. At the end of the topic, I provided the code for the stopwatch and some directions that you can use to start and finish it.

something like

local timeToComplete = 0
local finished = game.ServerStorage.CurrentPlayerCompleted
repeat
wait(1)
timeToComplete = timeToComplete + 1
until finished == true

use tick() to record the time when it’s fired.

What you need is to record the start time and record the end time to calculate the time the players spent.

Like:

local Starttime = tick()
wait(10)
local Endtime = tick()
print(Endtime - Starttime)

The output will be 10 because it waited 10 seconds to record the end time.

If you want to make a running timer, you can use RunService.Stepped:Connect() or RunService.RenderStepped:Connect() to see how much time did you spent on the obby currently. In other words: It’s recording the end time very fast and put the result on the GUI during you are running an obby.

1 Like

Just to point out, if you’re using wait(n) its probably going to yield longer or quicker than 10 seconds, the print function will tell the difference.

It’s always faster than 10 seconds, but about 5 milliseconds.

1 Like

image

This is probably because it took me some seconds to load into the game but idk

I tried again with your code, I loaded into the game really fast but this time I had 3 seconds delay
image

Yeah, if you run it in the console bar you can see the difference of a few milliseconds

1 Like