For loop is broken

for i=1, 0, -.05 do
	local Clone = script.Parent:Clone()
	Clone.Parent = Effects
	Clone.Position = UDim2.fromScale(i, i)
	wait()
end

this should put a clone at 0.95, .9, .85, .8… and so on but instead it’s doing this.
Cloning like 5 in one number.

Add a number inside that wait that fits it correctly because waits without numbers run infinitely

Not sure if that’s the case did. wait(.01) and it’s still happening.

Should a .5 fix it I haven’t tested it out yet tho

It’s best not to use non-integers in a for loop because you can miss your last iteration
because of a float’s inexact value (integers, within reasonable range, will be exact.)

1 Like

From the script you have given, the for loop works fine. You will need to provide more context in order to debug your script. For example, even though there is nothing that deals with transparency in the script you have given, the video you showed does have transparency.

But, the way I’m handling it, it should stop at a 0.

The Bar it’s cloning has transparency on it by default.

Also, this is all the code is.

local Player = game:GetService("Players").LocalPlayer
local Effects = Player.PlayerGui.MainMenu.Background.MainFrame.Effects

for i=1, 0, -.05 do
	local Clone = script.Parent:Clone()
	Clone.Parent = Effects
	Clone.Position = UDim2.fromScale(i, i)
	wait(5)
end

What part is broken. Everything is happening accordingly. As you said, it puts a clone at 0.95, 0.9, 0.85, 0.8…
I also ran the script you showed and there is no ‘non-integer’ problems.

The issue is that it clones WAYYYYY to many, you can tell it by the transparency, there should only be 1 cloned at each number.

Look again–I bet there’s no 0.

Club. Do the math. starts at 1, and -.05 until there is 0, there is no way that goes pass.
And this issue isn’t with it going to far, it’s the issue of cloning to many in 1 number.

I ran the loop and indeed 0 is not part of the output. Normally it should be, but apparently it skipped 0. It seems something happened along the lines of this:

image

I also figured out what was going on, I had the LocalScript running the for loop. So that’s why it was getting done over and over and over… you get it right? :eyes:

Weird, it worked and the math was right.

The way for loops work, the 0 should be there–Try 100 - 0 step -5

It working now :stuck_out_tongue:

That’s not what happens, when you call wait() with no arguments it waits the minimum amount, which is around 0.03 (and changes depending on fps).

1 Like

Can confirm in Studio Settings > Lua > Default Wait Time
image

1 Like