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

How to "fail safe" a script in the event something errors?

1 answer

✓ Accepted answer

Well the failsave is the built in pcall function which wraps everything inside it in a protected bit of code. If the code inside it errors it will return two thinks, a success value (boolean) and a error message(string) and if it is successful, it runs and returns a success value.

local success, Error = pcall(function()
	pprint("test")--errors
end)

if success then 
	print("yay",Error)--"yay",  false
else
	print(Error)
end

3 comments

1

you actually do not need to use variables.

1

well yes, but it is a little easier to understand in my opinion

0

Yes, this is a lot easier to understand

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