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

How do you find the sum of all numbers in a table?

How do you find add the numbers together that are in one table?

Weird Example:

local t = {1, 4, 6, 9}

print(t[i] + t[i])

The answer to this would be "20".

I have no clue on how to do that. Does anyone know how to add up all the numbers in a single table or arrangement?

1 answer

✓ Accepted answer
local t = {1,4,6,9} -- table

local total = 0 -- variable for the total

for i,v in pairs(tab) do -- iterate through the table and add on to the total
	total = total + v
end

print(total)

I don't know if there is any other way to do this, as I am not very good with tables, but this works.

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