Help with pcall-ing a function

I have 2 functions that choose 2 random players.
Sometimes the functions error when a player leaves stopping the entire game.

Is there a way make a function run without it stopping other than a pcall?
If not, then please teach me how to utilize pcall in this situation:

duel1,duelist1,duelseat1 = choose1()
--print(duel1, duelist1, duelseat1)
wait(0.1)

duel2,duelist2,duelseat2 = choose2(duel1)
wait(1)

I need the function to return the duel1, duelist1 and duelseat1 values instead of the success or error of function that pcall usually returns

You could pcall the whole block. you’ll still have to handle the case where the values do not get populated and retry.

You can also spawn threads to avoid the whole script crashing. task.delay(0 for example.

maybe if you show the choose1 and choose2 functions you can get better feedback

Try this (example for choose1)

local s,e,d1,du1,du2 = pcall(function()
   return choose1()
end)

Where the s,e are what pcall returns and the rest are what choose1 returns

You should, really, just put in a player check within the function.

But, if you want to pcall it, it should look like this:

local success, duel1, duelist1, duelseat1 = pcall(choose1)
--if an error is thrown, the variable 'duel1' will hold the reference to it

local success, duel2, duelist2, duelseat2 = pcall(choose2, duel1)
--if an error is thrown, the variable 'duel2' will hold the reference to it