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

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

Asked by 4 years ago
Edited 4 years ago

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

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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!

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 DahWaffleGamer 37 — 4y
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 DarkDanny04 407 — 4y
Ad

Answer this question