Making my Speedrun Timer more accurate

Hello, I made a timer that looks like Robot 64 TA timer but i want to convert it to use tick() to make it more accurate.

My current code:

repeat
	task.wait(0.01)
	
	if not Plr.Vals.InLoad.Value then
		TA += 0.01
	end
until Completed == true

The InLoad BoolValue is set to true when the player dies and then false when the player avatar loads

I thought about using a table to save the time the player spent in loading and the remove it from the timer, but idk how would i get the time the player spent loading

Any help is appreciated.

I would just recommend you use the magic of coroutines like this.

local TA = 0
local Run = game:GetService("RunService")
local coro = coroutine.create(function()
    while true do
        local waittime = Run.Heartbeat:Wait()
	    TA += waittime
    end
end) 
coroutine.resume(coro)
Plr.Vals.InLoad.Changed:Once(function()
    coroutine.close(coro)
    print(TA)
end)

(this is if you want to have a time that constantly updates)

The easiest way would be to just save the start time in a variable, and then record the end time in a different variable when Plr.Vals.InLoad changes. This won’t be limited to the server Heartbeat.

-- Get the current time
local startTime = tick()

-- Wait for the Changed event
-- Alternatively you could connect this to a function 
Plr.Vals.InLoad.Changed:Wait()

-- Get the time after the player has loaded
local endTime = tick()

-- The loading time is easy enough to calculate
local loadTime = endTime - startTime

i suggest you taking a look at tick()