Is it ok to not use pcall in important scripts?

  1. What do you want to achieve? know if there is a problem with not using pcall in datastore/gamepasses scripts etc.

  2. What is the issue? I usually don’t use pcalls in my script because it looks complicated a bit.

  3. What solutions have you tried so far? I usually see that my scripts works fine so that’s why I didn’t focus on pcalls a lot.

I also used to think pcalls were complicated, but they are way more simple than they look. Just assign the pcall to a bariable that has success and errormessage and then create the function from there.

That sounds like it doesn’t really explain what pcall is

I know, but it’s really hard to give examples on mobile

In my opinion (I think), pcall is a function that prevents the script from being terminated when the function in it errors.

Definitely use pcalls on datastores, not sure about game passes thought

So not using pcalls in datastores can really be a problem?

Sometimes datastores can error, sometimes it doesn’t.

Use this to help with pcalls, specifically in datastores

local success, errormessage = pcall(function()
-- whatever function
end)
if not success then
warn(errormessage)
else
-- code
end

That is complicated?

A pcall just provides two variables and doesn’t immediately error if something happened wrong.

Yeah, because if there is an error, it will completely stop storing data

sorry for going off-topic but, how do you reply to specific messages

Highlight it, it will give an option to quote

image

So basically I use pcall for example in saving and loading datastore put the function after the pcall, and put the code that is inside the function in the else or if success right?

For the if not success, print the errormessage, don’t repeat the code

And for the else, you don’t really have to do much, maybe just print “success” or something

Usually, people use pcall to wrap very important and prone to error code. It ensures that if there is an error, the rest of the program does not completely stop.

People use pcall in datastores especially because Roblox servers tend to go down, and usually that can also affect datastores. If there’s no datastore to retrieve data, then the program will return an error; stopping the rest of the script from continuing.

That is the main example, but you can also use it for various other reasons similar to that. For example, gamepasses or retrieving assets from Roblox; since those can also be affected from the Roblox API failing.

The general idea of pcall is to be used when you can expect that an error may occur due to an external source (i.e. Roblox servers). Of course, you are not required to use pcall, but it is good practice.

I have provided a post that goes into more detail about how and when you should use pcall.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.