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

How to make a for loop last a certain length depending on the amount and length?

I have this code wich SHOULD work but it doesn't. So, lol, plz help :))

local amount= 180 --the for loop number
local length = 5 --how long it should last
for i = 1, amount do 
	wait(length/amount) 
end

I will mark you as answer if you can help, thx!

1 answer

Haha there's a little mix up going on here.

local amount= 180 --the for loop number
local length = 5 --how long it should last
for i = 1, amount do 
    wait(amount/length) 
end

It technically was doing what you told it to do, 5/180. What I think you meant to do was 180/5, so I have changed up the order in the division.

Also, the 180 in this case (the amount) is how many times it will run through your code, just if you were unaware

Hope this helped!

2 comments

0

Hello, unfortuantly, I actually was trying to do length divided by amount because I wanted the for loop to last the length of the length variable. If I were to do it the other way round, it would wait 36 seconds between each wait lol

1

Ohh, well for loops are used to run through something a set amount of times, so you can’t really set how long you want it to last for, and there’s really no set time built in to a for loop. The way that you have it right now is that it runs through the loop 400 times and waits .027 seconds before it runs again

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