If this fails how do I make it not make an error and stop my code?

So basically I have a thing that can sometimes fail

Which is this

game:GetService('StarterGui'):SetCore("ResetButtonCallback",false)

Sometimes it fails so I need to know how to make it so if it does fail it wont stop the rest of the code after it.

Cause I dont know how to lol

1 Like

You would use a pcall. A pcall is short for protected call and is used for calling functions that may possibly error so that it does not stop the script and we can handle it manually.

local success, errormessage = pcall(function()
    game:GetService('StarterGui'):SetCore("ResetButtonCallback",false)
end)

if success then
   print("Success!")
else
   warn(errormessage)
end
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.