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

Is there a wiki page for pcall(function()?

I like to read random code in my free time and try to learn new things. Is there a wiki page for this line:

pcall(function()

If there isnt a wiki page could somebody give me a rundown of this line :)

2 answers

✓ Accepted answer

There is a wiki here

But I'll still explain (like I always do)

pcall is to catch errors, wich means that if your script would error, pcall will tell you that error, and just continue with the script.

This is very handy for things like datastore and remote functions.

You can make a pcall function like this

function apple()
	print('apple')
end

local success, message = pcall(apple) -- DO NOT ADD '()' AFTER THE FUNCTION!!

if success then
	-- Your code worked!
else
	print('Your code didn\'t work, error:'..message)
end

If you did for example this

function apple()
	prit('apple')
end

local success, message = pcall(apple) -- DO NOT ADD '()' AFTER THE FUNCTION!!

if success then
	-- Your code worked!
else
	print('Your code didn\'t work, error:'..message)
end

It will continue the script and will print you the error (if you want, you can use warn() so you can see it easier)

The other way is this

local success, message = pcall(function()
	print('Hey')
end)

And you can do the same with the success, and message variables it returned

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