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

What does return do?

So, I've noticed in some more, "advanced" code I've read through, there is an argument called return. I'm just starting out with Lua coding, I've asked friends but haven't really understood the function of the argument. Can someone clarify what "return" does?

1 answer

The return keyword is used in functions to send data back to the place where the function was called. Here is an example:

function divideBy(x,y) --initiate a function to divide x by y.
	return x/y --send the answer back to the place the function was called.
end
local division=divideBy(155,5) --division is now equal to 31!
print(division)

You can learn more about the return keyword here. I hope this helped!

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