How to use return?

Hello Devs!

I’m learning how to script better but I still don’t know how to use return.

I never used it and I don’t know how, where and when use it.

I watched some tutorials about returns but it’s still confusing

I will be happy when you will tell what is it and how to use it and give an example!


Here it is: Returning Values

1 Like

It just allows functions to return a value

local function sqr(num)
  return num^2

local num = 4

local squared = sqr(num)

print(squared) -- 16

Yes, and and also allows to end a function

local DoTheFunction = false

function Nice()
    if not DoTheFunction then
        return "NotNice"
    return "Nice"

local Return = Nice()
print(Return) -- returns "Nice" or "NotNice" depending on DoTheFunction