! Assist Needed | Directing Error to lines outside the module script

Hello there, thank you for taking the time to read and assist me on this journey!


I’m creating a public module called “BanService”; which is a module script
written in OOP with RBXScriptSignals and RBXScriptCallbacks.

I’m trying to create a system to help make it user-friendly. If you write an incorrect argument type within an RBXScriptCallback parameter, it’ll error and direct to the script where you wrote the line instead of the module.

I’ll cut it so it’s small but the bottom line is I want to create an error system that will error and display the line where the function written incorrectly or with incorrect argument types will display.

- BanService:9: Error Message Here           (X)
+ Your Script:LineNumber: Error Message Here (✔)

This is one of the functions for checking if a userid is banned:


--| Metatable
local methods = {}; methods.__index = methods

--| RBXScriptCallback
function methods:IsBanned(userid : number) : boolean --| Output is always boolean
	local success, output = pcall(function()
		if userid == nil then error("Argument 1 is missing or nil.") end
		if typeof(userid) ~= "number" then error(`Argument 1 is a {typeof(userid)}, expected Number.`) end

		local banData = DataStore:GetAsync(tostring(userid))

		if banData and banData[tostring(userid)] then return true end

		return false
	end)
	
	return success and output or error(output) --| Error will redirect to this line.
end

--| Code blow basically just other callbacks and an initiate function.

Explorer Context :books:


The TestScript is placed in ServerScriptService, where I run the code below to detect if a user is banned. The BanService module is placed within ServerStorage written in OOP.

local BanService = require(game:GetService("ServerStorage").BanService) --| Module
local TestScript = game:GetService("ServerScriptService").TestScript    --| Script

Current Output :x:


The following code is run from TestScript, which is a server script. Line 3 is the output.

local isBanned : boolean = BanService(851917460)     --| Correct
local isBanned : boolean = BanService("DonKingFrog") --| Incorrect and errors in the module where the function is written.
--| ServerStorage.BanService:9: Argument 1 is String, expected Number.

Required Output :white_check_mark:


The following code is run from TestScript, which is a server script. Line 3 is the output.

local isBanned : boolean = BanService(851917460)     --| Correct
local isBanned : boolean = BanService("DonKingFrog") --| Incorrect and must error to this exact line.
--| ServerScriptService.TestScript:2: Argument 1 is String, expected Number.

If there is anything I need to elaborate or restate in a different way, just tell me!

1 Like

For those that don’t want to read all of that, I basically just want to instead of erroring inside the module, error in the script where you wrote the incorrect function/argument types.

If I remember correctly, there’s a function for that

game:GetService("TestService"):Error(message, script_instance, line_number)
script_instance and line_number are optional

Thank you for the quick response, but how would I find the script and line where the function was written?

Never mind I have an idea for the script instance but the line number remains the question

for line idk how to do it in a way that isn’t goofy

for script, maybe if the module returns a table, the script requiring it will do something like this?

local module = require(module)
module.(insert something here) = script

honestly not too sure lol

the goofy method is to just add a line_number argument in every function lol

Even if you can’t explain, at least you reminded me of a crucial step for sending the error message!

one thing i think might work is a bindable event

I’m going to boost this since I still need a solution.