Ad
Log in to vote
1

This is not a question but can someone explain to me what does a pcall do?

Asked by 18 days ago

..................................................................

1 answer

Log in to vote
1
Answered by 18 days ago

I will attempt this question, my info might not be 100% accurate, but here’s what I know.

pcall stands for protected call, errors that happen in a pcall will not yield the rest of the script. It is commonly used when getting data, such as DataStore or HTTPService.

With pcall, Both print() will run:

print('before gibberish')

pcall(function()
    insert gibberish that errors
end)

print('after gibberish')

Without pcall, First print() runs, second print() doesn’t:

print('before gibberish')

insert gibberish that errors

print('after gibberish')

You can also get the error message and if the code inside pcall actually error’d.

local success, response = pcall(function()
    gibbersh stuf
end)

if not success then
    print(response) --print error / response
else
    print('no error / response')
end

Check out these links for better explainations and more info: https://devforum.roblox.com/t/pcalls-when-and-how-to-use-them/393687 https://devforum.roblox.com/t/pcall-function/1264795 https://devforum.roblox.com/t/pcall-xpcall-and-ypcall-tutorial-how-do-they-work/1417471 https://devforum.roblox.com/t/what-is-a-pcall-function-and-how-do-i-use-it-and-when-should-i-use-it/1710582

Ad

Answer this question