Basically what I want to do is to use values to do some math. Something like Prime Factorization to find out the index notations of a number. Here is my script.
Number = 200 Divide = 2 for i = 1,5 do wait(0.5) local result = print(Number/Divide) local Divide = Divide + 1 end
The output is just 100 and multiple of it. I do know that line 7 is the cause as it doesn't add up. Any way to add a number to a value? Thanks in advance.
What happens in your code is for every iteration in the loop, it creates a local copy of the Divide
variable, then adds 1 to that copy, instead of the Divide
variable you defined first outside of the loop.
The solution is to simply remove the local
keyword on line 7.
Really though, the error here has to do with scopes and stuff. When you define a variable as local, what happens is it's only accessible inside the scope or "block" of code that it's running in. This could get technical really quick, so I'd suggest you read this instead.
Hope that helps!