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
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
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
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!