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

How can I make a table with numbers in it add all of it?

So I wanted to know how to make a table add numbers inside of it, for example

local table = {1, 2, 3}

becomes 6 in the end

Ask me more questions if you still don't understand :)

1 answer

✓ Accepted answer

Simply iterate through the table with pairs and add each value to a variable:

local function AddTable(Table)
	local Total = 0
	for _,Value in pairs(Table) do
		Total = Total + Value
	end
	return Total
end

local TableToAdd = {1,2,3}
print(AddTable(TableToAdd)) --> 6

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