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
https://www.lua.org/pil/4.4.html
Please refrain from asking these kinds of questions on the forums. The forums are more meant for questions that you can't just search up easily.
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!