Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Can someone help me understand what is returning, a good example?

I see returning a lot especially in functions, what does it do? Is it useful? Any explanation is appreciated.

2 answers

✓ Accepted answer

Returning is used to send informations back to where the function is called, here is an example:

local function sayHi()
    return "Hi!"
end
-- Print returned value of sayHi
local returnedValue = sayHi()
print(returnedValue)

Here is the expected output:

Hi!

You can also return using integers, as well as performing arithmetics.

local function multiply(x, y)
    return x*y
end

local returnedValue = multiply(5, 5)
print(returnedValue)

25

Returning is very simple and easy to learn and very useful.

You don't have to wrap in a variable print(multiply(5, 5))

Quick Recap: Returning is used to send informations to where the function is called, so whatever your returned value is, that value will get sent.

1 comment

0

Ah I get it! Thanks for help my friend!

This discussion is preserved as it was. New answers, comments, and votes are closed.