What's a good scenario for a "for loop"

Yes my apologies, you can use a + instead of a *. LuaGoats, I know haha. I figured if they’re a beginner then I would show them the easy way first.

1 Like

so for the transparency one it would go up by .1 until it gets to 1? i think im starting to understand it now.

It’s useful for mathematical iterations or sequences that you want to iterate by a specific amount instead of using an epsilon for accuracy, such as a fibonnaci sphere or tilings.

3 Likes

Yes, so for the first loop, the transparency is 0.1, then for the 2nd loop it’s 0.2, the third is 0.3, etc…

1 Like

yeha i was gonna say haha might crash or something. idk bout crash but it would get pretty crazy.

im starting to understand! breakthroughs bro haha. i love scripting. so what whats a good example if you were getting information? i cant think of a good scenario

Nope, it works totally fine haha. I also made a cool one where you can dim all the lights in your game.

for i = 255, 0, -1 do
game.Lighting.Ambient = Color3.fromRGB(i,i,i)
wait(0.01)
end

1 Like

oh okay. thank you for the information!

dude you can do -1 as increment and have the start be a high number then low number. thats cool. yo everone is being so helpful. thank you. so much value.

Yessir! A good starting point is make a game where if the player touches a brick, they start to fade away. Or you can do is you can put a bunch of parts in a folder, use a for i, v in pairs loop and have them fade away periodically. That’s a solid example.

1 Like

oh that’s awesome. i’m starting to understand more. i’m going to write some scripts to better understand for loops. this already has been so helpful. i now understand a lot more.

i almost never use the first example of for loops

1 Like

lol yo that’s funny. character fades away when touching a brick.

the one where there’s an increment?

yeah i know that one. getchildren if child:isA(“yoda”)

Haha, you’re on the right track. That would work too. In this case it would be:

local player = whatever
local character = player.Character

for i, v in pairs(character:GetChildren()) do
if v:isA(“BasePart”) then – Or whatever a body part is.
for i = 0,1, 0.1 do
v.Transparency = i
end
end
end

1 Like

omg. im sorry to everyone who had the answers for this post. i wasnt going to put a solution because so many people were being so helpful but what this guy just put made so much click inside my head. i had to put it as the solution.

for loop inside of a freaking for loop. love it. so much just clicked for me rn haha.

1 Like

when i do the for i = 0,1,.1 do loop it does one part at a time. how would i make it so that it does all the parts at once?

So if you wanted all the parts to happen at once, you wouldn’t put a wait in between.

1 Like

well i tried that and it does the loop instantly but i think that it still does it one at a time. i made a new topic if you wants to transfer over to that one. my script is there as well