How can i create this into a somesort of script chain?

  1. What do you want to achieve? Keep it simple and clear!

Title says it all. I need a way to create this script into a chain of somesort.

  1. What is the issue? Include screenshots / videos if possible!

Im not really sure how id pull this off. I want the method “Catch” to fire if the function given to “.Try” fails.

I couldnt really find anything related to my question when i was searching for info. So im kinda stuck. Any help is really appreciated

Module code(Almost nothing because im stuck)

local module = {}


function module.Try(Func)
	
	local Sucess,Err = pcall(Func)
	
	if not Sucess then
		print("Fail")
	end
	
	return module
end


function module:Catch(Func)
	
end


return module


this is how I would do it (not tested).

local module = {}
module.__index = module

function module.Try(Func)
	local Sucess, Err = pcall(Func)

	return setmetatable({ Sucess = Sucess, Err = Err }, module)
end

function module:Catch(Func)
	if not self.Sucess then
		Func(self.Err)
	end
end

return module
1 Like