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

how can i return 2 vars at the same time?

Asked by 8 years ago
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

0
Edited to add code block BlueTaslem 18071 — 8y

1 answer

Log in to vote
1
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
8 years ago

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.

0
variable named Four 1waffle1 2908 — 8y
0
ty so much User#9293 0 — 8y
0
Thanks 1waffel1, forgot the quotation marks BlackJPI 2658 — 8y
Ad

Answer this question