Roblox Floating Point Number Error Interfering with For I loop

I’m trying to make a for loop that iterates over a table of parts and changes the transparency of all of them at once. Everything is working fine; however, the i value in my for loop is outputting as 0.950000000000003 on the final iteration, causing the script to not run again, thus not making the parts fully transparent. Is there any fix I can do other than hard-coding an extra iteration of the loop?

for i = 0, 1, math.round(0.05*100)/100 do
	i = math.round(i*100)/100
		for index, part in parts do
			
			part.Transparency = i
		
		end

	wait(0.01)
		
end

Can’t you just use tween service or?

just do this

for i = 0, 1.01, math.round(0.05*100)/100 do

I was thinking of that, im just not sure of how to tween multiple parts at once

for index, part in parts do
	game:GetService("TweenService"):Create(part, TweenInfo.new(0.3), {Transparency = 1}):Play()
end
1 Like

You just do a loop and then create the tween for each part. It would look like this:

for _, part in listOfParts do
    TweenService:Create(...):Play()
end
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.