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

What is difference between pcall and ypcall?

I never really used these call's or whatever they are called, little help will be very appreciated!

1 answer

pcall() is like your try catch block for other languages, but it has problems when used when yielding coroutines (the wait() function does this).

In roblox, you will generally want to use ypcall(), as this allows yielding across coroutines (using the wait() function inside a coroutine). They are used by passing a function.

For example;

pcall(function ()
wait()
end) -- will error

ypcall(function ()
wait()
end) -- will not error

--They are used like this:

if ypcall(doSomeDangerousFunction()) == true then
someDangerousFunctionSucceeded()
end

Click here for more information on pcall().

1 comment

0

I like this! though it would really help if you could please provide just one example :D. Thanks in advance.

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