To rerun the function, you just need to get if it is success or not, then use a while loop to rerun it until it is success.
local success, ErrorStatement = pcall( AFunctionToDoSomething )
while not success do
print("Error: "..ErrorStatement)
wait() --or a specific time
success, ErrorStatement = pcall( AFunctionToDoSomething )
end
Note: When the pcall is success, ErrorStatement will become the variable that is returned by the function.
Debatably. It really depends upon if it’s in a coroutine or not.
Just a heads up by the way @Quoteory: Repeatedly trying the same function until it succeeds usually doesn’t work out well and is a bad habit to get into. Try and avoid it if you can.
The thing here is that it depends where exactly you put the pcall, so it’s not necessarily a thread. There really isn’t any reason to nitpick the terminology either. It’s not relevant to the OP and a good number of people aren’t going to understand (or need to understand) that at a basic level.
Pcalls don’t rerun the function. Pcalls are genuinely used to prevent an error from breaking the script. But another thing about pcalls is that they have 2 very useful features:
Being able to see if it is a success
Being able to see the error if it doesn’t show one
The first variable that you type will return as true or false depending on if it was a success
The second variable will return the error message, but if the function was a success the second variable will always return nil(unless the function returned something)
You were wondering if it reruns the function. It doesn’t automatically do that. But if you put the pcall function inside of a repeat loop, and set it to keep repeating until (the variable you used to determine if it was a success) is true, it will keep doing the loop until success. It will probably look like this: