local Example = {
34,34,23,45
}
How would I go about adding all those to get one big sum
local Example = {
34,34,23,45
}
How would I go about adding all those to get one big sum
local value = 0
for i,v in pairs(Example:GetChildren()) do
value = value + v
end
print(value)
that’s what I could think of right now. Maybe I’m wrong and it doesn’t work
Alright let me test this out really quickly
It worked nicely thanks for the reply, I guess this is actually a suitable way to do it thanks
local Example = {34,34,23,45}
local Sum = 0
table.foreach(Example, function(i, v)
Sum = Sum + v
end)
print(Sum) --> 136
Example is a table, not an instance. You can’t use :GetChildren() on a table. The loop is enough.
Here is the fixed script from @Dolphin_Worm’s one
local value = 0
for i,v in pairs(Example) do
value = value + v
end
print(value)
i recommend using ipairs instead, but that should work