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

When Using Division It Makes My Script Values Inaccurate?

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 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

✓ Accepted answer

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

1 comment

0

Thanks, I just reached 100 rep :)

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