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

How do constantly add numbers without it being the same result?

Asked by 3 years ago
Edited 3 years ago

Hello, I need to be able to print() and make it so that it will count to 100. I was thinking like

1for i = 1, 100 do
2a = 0
3a = a + 1
4print(a)
5end

but that doesnt work

Thanks for the help!

An example of the output: 1 2 3 4 5 6 7 ... 99 100

It could even go past 100 to infinity, I don't mind. I just need it to infinitely add. Thanks!

0
Bruh. Dude. Just print i AlexanderYar 788 — 3y

2 answers

Log in to vote
1
Answered by 3 years ago

Your problem is that every time you run the loop you are setting a back to 0. Instead, do this:

1local a = 0
2 
3for i = 1, 100 do
4    a = a + 1
5    print(a)
6end

A pretty easy mistake to make and I'm sure everyone has done this before. Let me know if you have any questions about the difference between the two scripts.

0
Printing the value of the i variable would work too and it would use less code appxritixn 2235 — 3y
0
@phxntxsmic unfortunately there are scenarios that will be more complex than this and will require more than the i value. I decided to help him understand why the value of the variable didnt change cmgtotalyawesome 1418 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your answer.
1A = 0
2while true do
3      A = A + 1
4      print(A)
5      wait(0) -- change the 0 to however long you want the wait to be
6end

Answer this question