Basically, this just cancels the entire function ahead of time before the lines ahead of it can run
Say I have this:
local Variable = 20
local function CheckVariable()
if Variable == 20 then
print("This equals 20! CANCEL IT BEFORE THE FBI SPOTS IT")
print("This variable is not equal to 20, you're safe!")
In our if statement check, if a certain conditional check is true, then we can return (Or end) our function early since it’s our Variable is equal to 20 & will print that FBI statement
If it isn’t however, we can assume that the variable is pretty much safe since our variable is equal to something else!
but it only takes up a single line and doesn’t force you to indent your code. It’s good for a quick check at the top of a function to see if data is missing or some condition that would cause the function to error. It’s cleaner to abort rather than indent everything and match up another end.
A long time ago, I also didn’t understand when it was needed and it took a month to finally learn why I needed it.
This is when you need it.
local function AddNumbers(firstNumber,secondNumber)
return firstNumber + secondNumber
local onePlusThree = AddNumbers(1,3)
--return returns something to the item that calls it
local function countTable(tbl)
allowed = false
if not allowed then
--it can also end something