I’m trying to make the timer as accurate as possible, “task.wait()” has proven to be ineffective due to always delaying by a frame (about 0.0167 seconds), as an example, using it 60 times would increase the actual countdown time by an entire second, so RunService seemed to be a good option for accuracy.
Your code looks fine overall, only thing I would suggest is checking if the Cooldown_Number isn’t the same as the last one if you’re gonna be adding more code later on like visual effects.
local Last_Count = 0 -- add before event
if Cooldown_Number ~= Last_Count then
Last_Count = Cooldown_Number
Cooldown_Frame.Text = "Cooldown: "..Cooldown_Number
-- other code
end
For improved comprehension, contemplate using an identifiable constant in place of a magic number, such as 10 in math.round(Run_Time * 10) / 10.Moreover, for coherence, I advocate using camelcase.
I’m actually rounding so that the countdown can show decimals too, if I didn’t want decimals then I wouldn’t have to worry about the task.wait() delay, as it would be very unnoticeable.
-- Let's suppose that the current "Run_Time" is 3.333
-- 3.333 * 10 = 33.33
-- 33.33 (rounded) = 33
-- 33 / 10 = 3.3
print(math.round(Run_Time * 10) / 10) -- This would print "3.3"
Also, forgot to mention this, but “task.wait()” always delays by a frame, so “task.wait(2)” actually waits for something around 2.0167 seconds instead of 2 seconds.
You can still use a while loop. Just keep track of the tick() of when the timer started. Use an empty task.wait() and update the text to the difference between the current and initial tick(). Use a math.round() to help out that readability.
If you still don’t want to use a while loop with task.wait(), replace task.wait() with RunService.Heartbeat:Wait() to get the same effect.