✓ Accepted answer
Return
returns works the same way in coding as it does in real life. If a company sends something to you, but you don't feel satisfied with it, you return it.
In programming, the return statement is used as a final output of something. Once you've used a return statement, the scope your code is in ends there for the time being. This is why if you were to say something like this:
return nil
print("Hello world")
You'd get this error:
Error in script: '' expected near 'something'
Why is it important?
For reasons you may or may not already imagine, returning something for the right reason is very important. This can give code and input / output mechanic opposed to just providing input and getting nothing back. This is most typically represented through the use of functions.
For example, we could make a function that divides a number you input by 2, and return that value. But where does it get returned to? Let's take a look:
local function divide(n)
return n / 2
end
print( divide(10) )
This should answer our question of where data gets returned to, which is really something you'd quite expect. It just returns the value to where ever it was called. We can also take advantage of this by saving return values to variables, like this:
local function divide(n)
return n / 2
end
local result = divide(10)
print(result)
Hope this helped, if you have any questions, just let me know.