Doing math from an array?

How can I make the all numbers on a table to perform or add up or do math?

local numbersToStore = {1,3,6,2,6,100,335}
example: 1 + 4 + 4 + 1 = 10

for v,i in pairs(numbersToStore) do
– help, this piece of line needs some help pls i’m crying :(((
end

2 Likes
local numbersToStore = {1,3,6,2,6,100,335}
local sumResult = 0

for _, v in pairs(numbersToStore) do
    sumResult += v
end
2 Likes

Got a question, how to make division and multiplication works beause *= and /= returns 0, but subtract and addition doesn’t?

You could try *=. The reason that it was returning 0 might have been that you were starting from 0. Anything times 0 stays at 0.

local numbersToStore = {1,3,6,2,6,100,335}
local sumResult = 1

for _, v in pairs(numbersToStore) do
    sumResult = sumResult * v
end
2 Likes