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

In which cases would pcalls second parameter return nil even if the first one returned true?

So I have a script

local S,E = pcall(function()
	return DataStore:GetAsync(Player.UserId)
end)

if S then
	if E then
			
	
	
	end
end

-- Which situations would cause E to return nil even if the pcall's first parameter was true 

I know one way which is when GetAsync() returns nothing

But I was wondering if there was any other way E would return nil even if first parameter returned true

1 answer

✓ Accepted answer

The first return value is whether it ran without error. If there was is no error, it will be true otherwise it will be false.

The second return value is going to be nil if it ran without error (first is true) or be an error message depending on if one was given (as far as I know all errors with the language itself provide an error message, but calling error with no provided message of course won't give one).

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