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

When should I use pcall?

Asked by
Xternl 7
6 years ago
Edited 6 years ago

I get how pcall works, but I don’t get when I should use it.

2 answers

Log in to vote
1
Answered by 6 years ago

Use PCalls to handle things that could possibly error, such as datastores or Http requests, or if you're finding code doesn't work, you could do something like:

local success, err = ypcall(function()
    ppppppppppprint("i error!")
end)
if not success then
    print("Oops! I errored: " .. err)
else
    print("I succeeded!")
end
0
Thanks Xternl 7 — 6y
Ad
Log in to vote
0
Answered by
D3LTA_Y 72
6 years ago

This is a good tool for code errors, it is a good ally of a function if you want to keep track of what went wrong, you can use pcalls to keep track of your code carefully, putting one at each important step.

0
Thanks Xternl 7 — 6y
0
It slows everything down so no don't do it often. cabbler 1942 — 6y

Answer this question