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

how can i return 2 vars at the same time?

function boom(p)
	local check = nil
	local list = game.Workspace:GetChildren()
	for i=1,#list do
		if list[i].ClassName == p then
			return list[i] and list[i].Name
		end
	end
	
	
	
	
end
while wait() do
	local target = boom('Part')
	if target then 
		print(target)
		target():remove()
	end
end

basically i am trying to get it to remove 1 part and print the second return if i could get help dat would be cool

2 comments

0

Edited to add code block

1 answer

✓ Accepted answer

Returning Two Values

This is easily done by using a comma between the values for the return command:

local function Return2Vars(x, y)
	return x, y
end

print(Return2Vars("Hello", "World!"))
-- Output: 
--	Hello World!

But how can we collect these values and store them in variables? Well, this is also quite easily done by assigning two variables on the same line to that of the function call:

local function Return2Vars(x, y)
	return x, y
end

local x, y = Return2Vars("It", "Works!")
print(x, y)
-- Output: 
--	It Works!

Additional Note

For clarification, this works for any number of variables and is not just limited to two. For example, you could write return 1, 2, 3, "Four" and the integers 1, 2, 3 and the string Four would be returned.

3 comments

0

variable named Four

0

ty so much

0

Thanks 1waffel1, forgot the quotation marks

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