# Why does this happen?

Why does this happen when all I’m doing is…

repeat
Timers[Player.Name] = Timers[Player.Name] + 0.1
Timer.Value = tostring(Timers[Player.Name])
wait(0.1)
until Player.InObby.Value == false

The Timer is set to 0. It counts up in 0.1’s until the player finishes the obby. The server sets the timer value to an IntValue instance in the player. This is what the client changes it to on .Changed().

1 Like

Would you like the numbers to be rounded?

What you’re seeing here is a floating point error. Read up more on it here: https://floating-point-gui.de/

To summarise, for numbers to be stored in a computer system they must be stored in binary. In floating point binary, some numbers are unable to be represented accurately with a given number of bits. When this happens, the number may not be represented completely accurately but is often very close.

1 Like

Yeah, to 1 decimal place preferably.

For timers, I strongly recommend doing a for loop instead of repeat until…

For example.
the first number is the start, second is the last, and third is the interval. So you can easily set it to do it to the .1 interval.

for i=1,30,1 do
print(i)
end

it will print.

1
2
3
4
5

and so on.

How would I then stop the loop when they finish?

Use the break command.

for i=1,30,.1 do
if i >29.4 then
break
end
end

This will print until it reaches 29.4 then it will stop.

To round to the nearest tenth is actually pretty simple, just use this:

math.floor((number*10)+0.5)/10

Replace number w/ the number and it’ll return the rounded answer

3 Likes

So in my case, I could just do

for i = 0, 100000, 0.1 do
if player finishes obby... then
break

Exactly, You can also use it in the reverse for like intermission timers…

for i=30,1,-1 do
print(i)
end

it will constantly countdown from 30, very good thing to keep in mind.

1 Like

Awesome, that should fix it. Thanks

1 Like

This application shown in the post is more like a stopwatch rather than a timer, it’s perfectly acceptable to use a repeat ... until ... loop in this case as it’s counting up indefinitely, until a certain condition is met.

3 Likes