How do I fix this timer?

Right now I have a timer that uses tick() for a race timer. So I send an event to the client to store the start time, and then every frame I calculate the time elapsed since the race started with tick() - startTime.

But the problem is that the time on the server and client is not the same so I always get an offset, how would I fix this?

I know that I can tell the clients the server time every frame but that is very slow.

1 Like

Please provide us the code itself

1 Like

Calculate the time on the server, and update a variable such as an int value in the replicated storage. Whenever the client needs the information, it can just grab the IntValue’s value from the replicated storage.

1 Like

You can create a number value then set its value from server
then get the timer from client?

2 Likes

But that is still about the same as I said that I didn’t want to send something over to the client every frame.

1 Like

I want to have milliseconds showing on the timer so that’s why I need to update it every frame if you’re wondering.

1 Like

How did you get startTime?
char

1 Like

I send it from the server to the client.

1 Like

No like, did you run tick() - tick() as soon as the race started? or something

1 Like

First when the race starts I send the server’s tick() to all clients to store as the startTime variable and then on the client every frame I update a TextLabel to show the time with tick() - startTime.

1 Like

So startTime is equivalent to tick() when startTime was defined as tick()? I’m assuming which was as soon as the script ran.

1 Like

Yes, startTime is equal to what tick() returns when the race started.

Okay, so to get it to match up, you’d have to find the players’ timezones and convert them all to one, and there’s tons of tutorials on how to get timezones, and to convert it all to one timezone, just minus hours from tick() depending on the player’s timezone.

2 Likes

Gonna try this, do you know any easy way to do it?

An easy way to fetch timezones from the players?

Yes, exactly what I meant by that.

I found this tutorial Timezones In Scripting

1 Like

Thanks a lot, hope this works now!

For anyone searching for this in the future i found a much better solution by using roblox’s DateTime API. This also allows me to format time as a bonus!