The return will stop the rest of the function from running. This is good if the bool variable will cause the function to error. I believe the official name for this technique is known as a “guard clause”.
Both do the exact same thing, the only difference is in the first function after the return, nothing will run, and the function will be exited. In the second function, however, things below the if statement will still continue to run.
This is called the “guard clause”, improving readability and decreasing the chances of creating spaghetti code. I advise you to use them as well.
(Plus, it also decreases the chances of some bugs appearing in your code)
What everyone else stated is correct. This also prevents you from having to constantly type extra things such as doing absolutely nothing besides printing something if you hate having empty spaces like I do. I just looked into returning just today, and I can confirm that what everyone else is saying is true. It can also be used for returning Instances back to their original variable too, I think. That last part might not be true. Correct me if I’m wrong.
IsAFriend = nil
local Friend = script:FindFirstChild("Jack")
if not Friend then
return IsAFriend
end