Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

What does the syntax return do ?

Asked by
Kozero 120
10 years ago

Like this for example:

function Hello(name)
if true then
--code
return name
end
end

2 answers

Log in to vote
1
Answered by 10 years ago

Ok, so you have a function to make a part, for example:

function make()
local x = Instance.new("Part", workspace)
--stuff to make it nice
end

And now, lets say that we want to edit it later in a script.

make()
wait(5)
workspace.Part:remove()

Well, how do we know what part it is? We can't do workspace.Part, because there might be other parts there, and that wouldn't be a good thing, removing the wrong part. So lets add a return:

function make()
local x = Instance.new("Part", workspace)
--stuff to make it nice
return x
end

What this allows us to do is it allows us to store what we return in a variable, like this:

local b = make()
wait(5)
b:remove()

You can also return multiple things:

function make()
local x = Instance.new("Part", workspace)
--stuff to make it nice
local y = Instance.new("Part", workspace)
--stuff to make it nice
local z = Instance.new("Part", workspace)
--stuff to make it nice
return x,y,z
end

local a,b,c = make()
wait(5)
a:remove()
b:remove()
c:remove()
Ad
Log in to vote
-1
Answered by
war8989 35
10 years ago

It's returns a value. So if you were to do:

myname = Hello("war8989")
print(myname)

It'd print "war8989".

0
Yup! war8989 35 — 10y
0
Hang on this is not want I'm asking for.I want to know how I can use it. Kozero 120 — 10y

Answer this question