Im wonder if roblox has something like pythons
try:
print(“hi”
except:
warn(“error”)
the try except function is where in the try, you put in your code and if theres an error instead of stopping the script it goes to the except: where u put a print saying it errored or something
1 Like
you can use pcall and go like if success then do stuff that you want , else dont do it
1 Like
Like @whatplayer5858 mentioned, use pcalls.
local success, output = pcall(function()
--.. do something
end)
if success then
-- it was successful
else
warn(output) -- send the error
end
1 Like
you can use xpcall() for that
xpcall(function()
end, function()
-- this function will run if the function above throws an error
end)
1 Like
You’d use pcalls or (more preferably) xpcalls.
function source(a, b)
assert type(a) == "number"
assert type(b) == "number"
return a + b
end
function msgh(msg)
warn("Error Occurred: " .. msg)
return nil
end
xpcall(source, msgh, 1, 2)
xpcall(source, msgh, "test", 2)