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

Is it possible to make a function or ModuleScript return multiple values? [SOLVED]

Let's pretend I have a ModuleScript MultiReturnModule.

It has two things that it wants to send to other scripts: the value PartCount

PartCount = 0
for i,v in pairs(Workspace:GetDescendants())  do -- doot
	if part:IsA("BasePart") then -- if izza part
		PartCount = PartCount + 1 -- 1UP
	end
end

and the boolean

true

Is it possible that it could return both of these values having to group them together and probably putting true into a variable? (what I'm thinking here on the question: return PartCount, true)

######Note: I respect that many ROBLOX built-in functions return multiple values, and I argue that they're custom functions made by ROBLOX, and they're mostly coded in C++, so... ye

1 answer

✓ Accepted answer

Yes you can do that. Example:

function numx2(x)
	return x,x*2
end
local orig,x2 = numx2(8)

print(orig,x2) --> 8 16

Sorry for the weird example just thinking off the top of my head.

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