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 mean? What do you use it for? Why is it useful?

Hello guys. I have question. I can't understand what return means. So I'm wondering what return is. What is return? Why do you use it? Why is it useful?

I want to know that. If you can help me, thank you,

Ducksneedhelp - New Scripter

3 answers

Hello returns are useful for a lot of things like if using a RemoteFunction you can example as : Ask the server for the clients money in the data base or information about the server , server-sided things, etc.

function getme()
	return 1+2
end

print(getme) --would print "3"

function myname()
	return game:GetService("Players").LocalPlayer.Name
end

Well basically it's in the name "return" that's what it's used for to return strings,values,int's,tables, even functions sometimes depends on how you want it and what you do with it.

or as Crazyman32 said :

Example from real life:

You go to a restaurant and order a sandwich and a drink. A bit later, you receive the sandwich and drink. In other words, you gave the restaurant input (your order) and it in turn gave an output (sandwich and drink).

The process of the restaurant outputting would be what return does. In this analogy, you are the caller of the function, and the restaurant is the function.

function Restaurant:OrderFood(orderInfo)
   -- Do some stuff to figure out the actual food
   return food
end

-- You, the customer:
local myFood = Restaurant:OrderFood("Sandwich", "Water")

Hope this helps, cheers!

2 comments

0

hey just wondering is return basically for checking something? like printing?

0

It's for returning information.

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