I understand how returns work but I don't understand what they are used for. If a person and print a variable to they output, why would they want to return it instead?
✓ ANSWER ACCEPTED
Can someone explain what returns are for?
1 answer
✓ Accepted answer
return is used in functions to stop everything (loops, etc.) and, literally, return a value.
function add(a, b)
return a + b
end
local sum = add(2, 2)
print( sum ) -->4
So basically, add runs, then it gives us the sum. This lets us set a variable to the function's result, as we did on line 5.
Comment with questions.
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
Thanks, so then what could you use that variable for?
The 'sum' variable equals what the function returned - in this case, it's the result of the addition. We use it to store the result, so we don't have to keep calling add() each time we want 2+2; we can just use the variable.