Stopwatch in decimals

Hello Devforum! I have come with another simple question. How could I make a stopwatch counting in decimals? I have already got it set up, but I do not know how to get it to count in decimals every second. This is what I have so far.

while wait(0.1) do
				if hit.Parent.Humanoid.Health > 0 then
					player.Timer.Value = player.Timer.Value + 0.1
				else
					print("Break loop")
					timerdebounce = false
					break
		
				end
			end

As you can see, this will count the timer slower than a second should count.

2 Likes

What do you mean by this, if you count every second, you will have no decimals.

1 Like
  1. Is “timer” an int or number value?
  2. Why not use HealthChanged or GetPropertyChangedSignal instead a while loop?

(I just now read what you want to achieve here)

1 Like

So, I am trying to make it so that the timer will count up in decimals to seconds. I do not know if this makes sense, but yea I am trying to make it go up by decimals to seconds. Like 0.01 to 1.

1 Like

Timer is a numbervalue and not an int value. I am not sure HealthChanged or GetPropertyChangedSignal can be used in this situation.

1 Like

You are checking for the targets humanoid health, you can absolutely use one of them.

About your question, there are other poats with solutions about rounding numbers/coverting them from 0.01 to 0.1when needed, etc.

Well actually no.

He’s making sure they’re alive, he’s not counting only when the health changes.

1 Like

domboss37 is right. I am only checking if the player is alive.

Try walking through this tutorial and seeing if you can extract the timer function:

Is this stopwatch just for display purposes? (is the logic happening elsewhere?)

If so, you may want to consider using RenderStepped. The issue with your current implementation is that wait(0.1) is highly unlikely to actually wait for exactly 0.1 seconds, as it’s only accurate to 0.03 seconds, and is not meant for measurement of time. RenderStepped, however, passes the delta (time passed) between frames, providing you an accurate readout of how much time has passed without having to update the timer value unnecessarily (you don’t need the timer to update between frames).