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

Why does this loop not terminate?

Asked by 9 years ago

This is really simple but I came across an annoyance I've had before where incrementing Transparency by 0.1 means it doesn't reach 1.


local Touched = false script.Parent.Touched:connect(function() if not Touched then Touched = true repeat script.Parent.Transparency = script.Parent.Transparency + 0.1 wait(0.1) until script.Parent.Transparency == 1 script.Parent.CanCollide = false Touched = false end end)

This code reaches 1 but doesn't terminate and just keeps getting larger. I've had the same problem with a for loop

for i=0,1,0.1 do
     script.Parent.BackgroundTransparency = i
end

Instead this code never makes it to 1. Is this some sort of floating point rounding error? Thanks.

MD

2
Try putting >= on line 8, instead of == Shawnyg 4330 — 9y

Answer this question