Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

When Using Division It Makes My Script Values Inaccurate?

Asked by 6 years ago

So below I have a script that creates a progress bar that increases at a speed by doing distance/Time. I also have a countdown timer aswell in a different script. One thing I noticed is that when I change <divide> to any other value, the bar is less accurate and is not synced with the countdown.

I am asking how I can make it accurate because I want to divide the numbers so it is a much smoother increase yet stay in sync with the timer. How can I fix this?

increase = 0
divide = 1

distance = 800
Time = 30

repeat
    wait(1/divide)
    increase = increase + (distance/Time)/divide
    script.Parent.Size = UDim2.new(0,increase,0,600)
until increase >= distance - 10

1 answer

Log in to vote
0
Answered by 6 years ago

Ah, it is just a simple error known as the roundoff error. Fix it by doing something like this and adding it to your script:

function Round(num)
    math.floor(num+0.5)
    return num
end
0
Thanks, I just reached 100 rep :) DeceptiveCaster 3761 — 6y
Ad

Answer this question