Timer system for levels?

How would I create a timer system that is specific to a certain level in a game? I already have spawns and endpoints set up per level so I can use those as the beginning and ending points for the timer, but I’m still not sure what the best way is to make it.

You could use the epoch unix time and using some math calculate the difference.

endTime - startTime = differenceInMilliseconds and to convert to seconds, minutes, hours, whatever, just divide appropriately or use some math functions, I’m sure some exist for this.

I am also sure there a time modules too, you should take a search for some of those if you want to save time.

Thanks, but do you know how I would set it up? I know how to script the actual time itself, but I just don’t know where to put the script and if I need anything else like a server script.

Are you able to give details on the sort of timer needed? Is it like a multiplayer obstacle race? Single player speedrun? Is it competitive or casual? There are different approaches you will want to use depending on the game style.

Well for now its just going to be a timer where if the player chooses a speedrun mode on a certain level from start to finish their run will be timed. I will also add leaderboards later, and a race feature although Im not sure if I should use this timer for the race feature or just check whoever hits the end first. The race feature will basically be 2 player I may add more that have to race through a level and whoever finishes first wins. Pretty much all of them will be competetive since the normal speedrun timer is for leaderboards and the race feature is obviously going to be competetive.

Alright, what you should do then is when a the mode or starting line is touched, it tells the server to start the timer. The server should then calculate the time, and when the end is touched it stops timing. This way the client cannot just cheat their times saying they finished in 0.000001 seconds.

You should also add checkpoints that are randomized too so exploiters cannot teleport to the end or just iterate through them (as some vehicle simulator hacks do). Do not trust clients when trying to get accurate times, or any accurate values in general.

K thanks, also do you know how I would make the timer specific to each level, I’m not entirely sure how I would make that, I already have a gui where you can select a speedrun mode, in which you can select a level. What I’m thinking right now is to make it so that if the player chooses a certain level it fires an event to the server in the endpoints script that checks the player’s stage leaderstat(which is set when the player chooses speedrun mode and the specific level) which then fires an event to another server script that is the actual timer itself to start the timer. From there how would I make the timer stop when the player hits the endpoint? Or is this the wrong way to do it in general?