Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

My GUI Timer is inaccurate, takes longer for seconds to pass?

Hi everyone!

I was making a timer which would start counting from 0, and go in milliseconds (similar to a speedrun timer). Here is what i tried to do:

if isRunning == false then
	isRunning = true
	local timer = script.Parent -- a text label
	local milaseconds = 0 -- totally correctly spelled
	local seconds = 0
	local minutes = 0
	while isRunning == true do
		wait(0.0001)
		milaseconds += 1
		if milaseconds == 100 then
			milaseconds = 0
			seconds += 1
			if seconds == 60 then
				seconds = 0
				minutes += 1
			end
		end
		timer.Text = minutes .. ":" .. seconds .. "." .. milaseconds -- no bad spelling here
	end
end

The timer ends up taking way too long, a second in the script is around 2.5 seconds irl. Can anyone please help me make this timer more accurate?

Thanks in advance :)

1 comment

0

I'd reccomend using RunService. It's faster and more reliable for things like these.

2 answers

The lowest wait() you can have is 1/30 of a second, if you wish to go lower, use RunService.Stepped/RenderStepped, which is 1/60 of a second.

1 comment

0

how would i implement this into my script?

Wait() is inaccurate and should not be used for precise timing. You should use tick() or runService instead

This discussion is preserved as it was. New answers, comments, and votes are closed.