#Return
1 messages · Page 1 of 1 (latest)
Hi im a scripter in roblox i have a few question of how to use return in roblox, but i dont understanding how to use it and when to use it, if someone could help me i will be very grateful
jk
try messing with it like you usually do with other stuff like functions
try putting it in different situations
and read about it
To explain it simply, "return" give the value back to the line it was called, for example your function
local function Adding(n1, n2)
local add = n1 + n2
return add
end
now, when you use the return it sends the value of add, and to where? let's say you make a variable,
local function Adding(n1, n2)
local add = n1 + n2
return add
end
local calculatorAdd = Adding(1, 5)
the value of calculatorAdd would be..
6
does this explanation make sense?
you can use return in many other ways, but to explain it in a nutshell, if gives back the value you "returned" to the line it was called.
i've heard return is used to escape or stop a fuction
yea you can use for guard clauses like if not player:HasEnoughMoneyToBuyStuff() then return end to end a function early, instead of having everything nested in an if statement in an if statement in an if statement end end end end end
that too