Ad
Log in to vote
0

How to use pcall? I'm pretty new to it [closed]

Asked by
anphu04 124
6 months ago

This question already has an answer here:

How does pcall, xpcall, and ypcall actually work?

I don't really remember how to use it, but I remember that people say you use it to not get errors or something...

:thonk:

0
You should only use pcall when there are errors that you CANNOT avoid, like the ones thrown by DataStores. You should not use pcall to "solve" your programming mistakes. BlueTaslem 16683 — 6mo

Marked as Duplicate by TheeDeathCaster, Vulkarin, and cabbler

This question has been asked before, and already has an answer. If those answers do not fully address your question, then please ask a new question here.

Why was this question closed?

1 answer

Log in to vote
0
Answered by
LuaDesign 207 Moderation Voter
6 months ago
local Success,Message = pcall(function() -- Success = a bool if it runs without error, Message is the error.
print("hey")
end)

if Success then -- Checks if it is true.
print("hey it worked")
else
print("Failed: "..Message)
end
local Success,Message = pcall(function() -- Success = a bool if it runs without error, Message is the error.
pritnt("hey")
end)

if Success then -- Checks if it is true.
print("hey it worked")
else
print("Failed: "..Message)
end
0
So what can this be used for? anphu04 124 — 6mo
0
Basically to surround a piece of code within' the pcall to continue the rest of the script even after it errors. LuaDesign 207 — 6mo
Ad