I was looking at my script and it looks a bit cluttered because of all the variables the pcall is using. And I was wondering, do I need the variables before it?
local success, errorMsg = pcall(function()
--code
end)
if success then
print("Success")
else
warn(errorMsg)
end
Well pcall returns those 2 variables, if you are using pcall without storing it then it will not detect what error you are getting pcalls are used to catch errors, you can try using xpcall, just its try {...} catch() {...} in javascript.
xpcall(function()
print('Hello world')
print(lets do an error) -- Error
end, function(errr)
print('there is an error')
error(errr)
end)
You even can get 2 variables from xpcall.
local success, data = xpcall(function()
print('Hello world')
print(lets do an error) -- Error
end, function(errr)
print('there is an error')
error(errr)
end)
if (successs) then
--code
end