Pcall not protecting against all errors

I don’t got a lot to say / type but does pcall not protect against all errors that could happen within the function?

I tried to wait for a child in a pcall so that if it inf yield the rest of my code doesn’t get affected but it seems to globally affect everything for some reason.

Example of how code was:

local Parent = path.to.parent
local Child = nil

local Succ, Err = pcall(function(...) 
  Child = Parent:WaitForChild("NonexistentChild") 

A pcall doesn’t run on a new thread. That wait will affect everything after it.

1 Like

Pcall are supposed to protect against all errors (what i believe) it doesn’t need to be a new thread

1 Like

All it does is run the code, and return a status based on whether or not an error occurred. It doesn’t ignore waits. It will exit if an error occurs, but an infinite yield isn’t an error, because you could just be waiting for the part to load later.

If you want it to ignore the wait, run it on a new thread.

1 Like

try putting the pcall into another pcall

1 Like

WaitForChild doesn’t error. So yes the pcall will wait forever and not ever claim there was an error that was skipped.


Don’t expect pcall to protect against all errors alone. The pcall is meant to be a logical structure to divert code from complete halt to handling the error. The thread continues without any failure after that.

1 Like

use task.spawn as infinite yields arent errors

1 Like

wow never thought of that

1 Like

My goal was to catch this tho…
It was like a GetChild method that would return the child by first using FindFirstChild then looping through children then the final wait for child