XPcall in module script

XPCalling a module script’s function

  1. It does print out the errors and stuff but it does not prevent the error from breaking the whole module, sometimes it prevents it, and most of the time it doesn’t

  2. ** I’ve looked everywhere but I did not find a method that works 100%

local module = {}
module.function = function()
game.workspace.Nothing -- a fault on purpose to test it
end

function Handler(bool,data)
player.PlayerGui.ScreenGui.Debug.Text = data
end
local success, data = xpcall(module.function,handler)
print(success,data)
return module

That might be the issue right there, it might not know what returnedData is

Maybe, I’ll test it and come back.

Still, doesn’t work at all for some reason.

Edit: This works i tried it

local module = {
	Player = game.Players.LocalPlayer	
}

local success, data = pcall(function()

end)
print(success,data)
print("e")
function ErrorHandler(t,e)

	module.Player.PlayerGui.ScreenGui.Debug.Text += t
end
return module

Edit: Doesn’t work apparently.

@wesam1992 Ok:

  1. 4 Variables were unspecified inside the module
    ActivateModel ErrorHandler player returnedData
    I specified player and replaced returnedData

  2. xpcall is a custom error handler while pcall catches errors and prevents them automatically


More Info here: Lua Globals | Roblox Creator Documentation

1 Like

Thank you very much for the explanation!

Actually, wait I just noticed that your solution doesn’t include the module.activate which I kinda need so is there any way? (if not then I’ll just roll with your solution up)

Is it a function? A RemoteFunction?

It’s a function that scripts can call

local module = {}
module.function = function()

end
return module

So it Is a RemoteFunction correct?

It’s not the instance called remote function but it is a remotely called function from other scripts

Inside module table add this:

local module = {
ActivateModel = function(model)
-- script here
end;
}

-- How to call function
module.ActivateModel()


return module

Hope this helped

1 Like

For anyone needing the actual code that works, It’s here

[/quote]
Thanks! I ended up xpcalling it inside of the function.


local module = {}
local Player = game.Player.LocalPlayer
	Function = function()
		local success, data = xpcall(function()
		
		local test = game.workspace.Nothing -- a fault on purpose to test it
		end,ErrorHandler)

	end;
function Handler(bool,data)
print(data)
end

return module

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