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

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

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

for i = 1, 100 do
a = 0
a = a + 1
print(a)
end

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!

1 comment

0

Bruh. Dude. Just print i

2 answers

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

local a = 0

for i = 1, 100 do
    a = a + 1
    print(a)
end

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.

2 comments

0

Printing the value of the i variable would work too and it would use less code

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

A = 0
while true do
      A = A + 1
      print(A)
      wait(0) -- change the 0 to however long you want the wait to be
end

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