if workspace.CurrentCamera:FindFirstChild'blur'~=nil then
workspace.Current.Camera.blur:Destroy()
end
And according to the logic, the pcall can return an error, that is, will it be worse in terms of code optimization or not? Or maybe there are any alternatives to this?
You shouldn’t use pcall to prevent errors you know you can solve yourself, such as in your example. Use FindFirstChild instead of simplying ignoring the error.
if, for example, the blur can be turned on in the settings, and it is turned on, “blur” appears in the camera, otherwise not. I think the “FindFirstChild” condition is too long, I don’t really like it:(
I know what can be used as a variable, I wrote it to make it clearer. But still, is it possible to use it just for shortening at least in small cases, or is it harmful?
Nope. A pcall doesn’t error except when u pass something that isn’t a function, and some other cases that you will rarely meet.
With that out of the way, pcall is good and FindFirstChild also is. Depends on the use case, one can be better than the other, in your case, I think that FindFirstChild would be a better option, it’s made for instances and should be used there, pcalls should be used in HTTPService, DataStoreService, etc.
pcall should only be used in situations where a failure may occur that is outside the control of the calling code. For instance, any service that has to reach out to Roblox (e.g. DataStoreService) should be wrapped in pcall, because it might throw an error, which is out of your control. This might also be the case when calling into user-created libraries that expect you to handle errors yourself.
Using pcall as a catch-all for code like FindFirstChild is not advised, as it might end up hiding actual issues with your code. In cases where your code fails to do what it is supposed to do, it should throw an error. Errors are your friend, as they show you where problems exist.
If the logic of your code is, “destroy this part, only if it exists,” then the code should explicitly be written like that.