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

How to use pcall? I'm pretty new to it

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:

1 comment

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.

1 answer

✓ Accepted answer
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

2 comments

0

So what can this be used for?

0

Basically to surround a piece of code within' the pcall to continue the rest of the script even after it errors.

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