for i = 1, current*10 do
if current == 0.1 then
wait(.1)
current = 0
MoveCooldown.Text = current
break
end
current -= 0.1
MoveCooldown.Text = current
wait(0.1)
end
local current = 5
for i = 1, current*10 do
if current == 1 then
current = 0
MoveCooldown.Text = current / 10
break
end
current -= 1
MoveCooldown.Text = current / 10
wait(.1)
end
This seems to be a reoccuring issue with different numbers, according to this old thread, with an explanation by Osyris.
In short, you might want to consider implementing (or taking, they’re available on the internet in public domain) a system which rounds out numbers for you as a possible solution. Hope I helped.
local current = 5 -- cooldown is 5 (example)
for i = 1, current*10 do
current -= 0.1
MoveCooldown.Text = current
wait(0.1)
if i == 0.1 then
break
end
end
You could do this if the last number is important but the next to last isn’t. It gives you the same 50 iterations but ends in 0.
local timeStep = 0.1
local current = 5-timeStep -- cooldown is 5 (example)
for i = 1, current*(1/timeStep)+1 do
current -= math.min(timeStep,current)
MoveCooldown.Text = current
wait(timeStep)
print(i, current)
end
or if you want nice numbers there is counting up time.
local n = 0
local timeStep = 0.1
local current = 5 -- cooldown is 5 (example)
for i = timeStep, current, timeStep do
n += 1
MoveCooldown.Text = i
wait(timeStep)
print(n, i)
end
P.S. I used a variable for your counter speed and converted all the numbers. Hope it isn’t confusing. Lets you change the speed with one number change.
local current = 5
local step = .1
local decimalPlaces = 1
for i = 1, current*10 do
current -= step
if current < step then
current = 0
MoveCooldown.Text = 0
else
MoveCooldown.Text = string.format("%."..decimalPlaces.."f", current)
end
wait(0.1)
end
If you are ok with the text displaying 0.0 then you can just remove the MoveCooldown.Text = 0
Although any solution is generally accepted with floating point issues. Just depends what you are preferring.