I've just started scripting and when I was learning about functions, I came across returns. I need help understanding what it does.
The return keyword returns a value as implied by it's name. Also, when return is called, the function stops and exits where it is at.
For example, if you wanted a function to give a result you could use the return keyword.
Say in this example, you want assign the value "Hello, World!" to a variable if a variable is true, using a function of course.
-- Script (on server) local var = true local function coolFunction() if var == true then return "Hello, World!" end return false -- You can also say 'return' instead of 'return false' end var = coolFunction() print(var)
In the example shown above, the var variable will be assigned the return value of the coolFunction function if it is equal to true. Then we print out var's value because why not.
Because var is originally true, it will return "Hello, World!" and not get to where the function returns false.
Output: "Hello, World!"
Marked as Duplicate by zblox164, Ziffixture, Fifkee, Gey4Jesus69, and DeceptiveCaster
This question has been asked before, and already has an answer. If those answers do not fully address your question, then please ask a new question here.
Why was this question closed?