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

How do I read multiple values coming from a function?

WorldToScreenPoint returns a Vector3 and a boolean. However, I can't read the boolean in any way I tried. How do I read it?

1 comment

0

For multiple return values you list the variable ie local vec, val = camera:WorldToScreenPoint(pos)

1 answer

To receive multiple return values, use multiple assignment:

local function getFirstThreeNumbers()
	return 1, 2, 3
end

local first, second, third = getFirstThreeNumbers()

Extra return results will be discarded:

local function getFirstNumbers()
	return 1, 2, 3, 4
end

local first, second, third = getFirstNumbers() -- Fourth return value discarded.
local anotherFirst, anotherSecond, anotherThird, anotherFourth = getFirstNumbers()
local moreFirst = getFirstNumbers()

Extra variables in multiple assignment will get nil:

local function getFirstNumbers()
	return 1, 2, 3, 4
end

local first, second, third, fourth, fifth, sixth = getFirstNumbers()
print(fifth) --> nil
print(sixth) --> nil

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