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

What does the syntax return do ?

Like this for example:

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

2 answers

✓ Accepted answer

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()

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

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

It'd print "war8989".

2 comments

0

Yup!

0

Hang on this is not want I'm asking for.I want to know how I can use it.

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