Question about pcalls

Hello, just a quick question about pcall. Say I have this code:

pcall(function() --let's say all of these are connections EXCEPT for "u6"
	u4:Disconnect();
	u5:Disconnect();
	u6:Disconnect();
	--say an error was thrown here because "u6" was nil
	u7:Disconnect(); --does the pcall stop because of the error above, or it just passes by ignoring?
	u8:Disconnect();
	u9:Disconnect();
	u10:Disconnect();
end);

If all of the variables were connections except for “u6” which is nil, would “u7” and the other connections after it be disconnected?

2 Likes

I believe it would just stop and return an error, then it would continue running outside the function.

1 Like

It would yield until it returns an error (attempt to call method :Disconnect() on nil, in your case) or it finishes the code, and then continue the rest, thats how pcall works

pcalls are like running a seperate script. If that script returns an error, your script would get that message and continue running. If it doesn’t, your script would not get the error and continue running. Additionally, you can add a return value at the end of the function. Your script would get the returned value and the error message, both stored in tuples.

1 Like

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