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

what is local success and other stuff?

Hello, I was going through roblox dev page reading about gamepasses then i came across a syntax which i did not understand but have seen it in many places. Can anyone pls explain me note that the below code is an example, i have seen it in many places the main part where i have doubt is the 'local success, message' part and also the pcall function can anyone pls explain me?

	local success, message = pcall(function()
		hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)
	end)

Thanks in advance, ayazi10

1 comment

0

Basically it calls the function, except if there is an error in the function, it wont stop the whole script because of the error. Instead, it will return success and the errorMessage. Success is a bool value, and if it is true, then the code inside the function ran without any errors. If success is false, it will also return an errorMessage, which is the error you would usually get (as a string)

1 answer

✓ Accepted answer

The pcall() allows you to excecute a function without getting an error.

Whatever code is inside the pcall will attempt to excecute the function. If the code was successfully excecuted without any errors, the success variable will be equal to true. If it was unsuccessfull, the success will be equal to false, along with the message variable being equal to the string which holds the error message.

The reason this is useful is because many Async functions can fail, and can error and break yoru script.

2 comments

0

omg thank you so much, i never imagined developers helping newbies building their game. Thank you so much, I really apreciate that

0

It doesn't matter who you are, you should always deserve help!

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