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

How would you go about adding number values in a table together?

I'm trying my hardest to create a rarity system in my game but can't seem to get it. I haven't yet settled on a way to correctly go about it, but what I have come across is a question. How would I go about adding number values within a table together? (I'm using a ModuleScript)

ModuleScript:

local module = {

	['Item List'] = {

		['Item One'] = 50,
		['Item Two'] = 25,
		['Item Three'] = 10,
		['Item Four'] = 5,
		['Item Five'] = 0.1

	}
}

return module

1 answer

✓ Accepted answer

Go through each value in a table, and add it to a variable. Then you can use that variable for whatever you choose to use it for.

local total = 0

for i,v in pairs(table) do
	if typeof(v) == "number" then
		total = total + v
	end
end

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