Attempting to allow module script users to set authentication key

Hello, developers! Yada yada yada.

  1. What do you want to achieve? I’ve got a module script I’m trying to make, and the use of this script requires an authentication key because it uses HTTPService to talk to an outside service.

  2. What is the issue?

--Module script in ServerScriptService
local module = {}
module.authHolder = nil

function module.setup(authKey: string)
    print(authKey) -- Prints authentication key
    module.authHolder = authKey
    print(module.authHolder) -- prints nil
end

return module

As noted by the comments in the module script, I can’t seem to change the variable no matter what.

--Regular script in ServerScriptService
local myModule = require(game.ServerScriptService.ModuleScript)
local myAuthKey = "literally anything at all"
module.setup(myAuthKey)

This is ideally how I’d like to set up the service.

  1. What solutions have you tried so far? Replacing module. with local , in front of authHolder, makes it turn into a circular reference to the module, somehow. It might be useful behavior, but not for this use case.

Does this as a local variable work? it will not lead to a cyclical dependency.

--Module script in ServerScriptService
local module = {}

local authHolder = nil

function module.setup(authKey: string)
    print(authKey) -- Prints authentication key
    authHolder = authKey
    print(authHolder)
end

return module

I also notice your runner script is calling module.setup when it should be myModule.setup

Even your minimal example works in a baseplate so I believe the issues lies elsewhere, try posting more of the real script you are using.

It looks like it was just text fatigue. Looking at the real script, it looks like I accidentally typed myModule:setup(...) when it should have been myModule.setup(...). I’m still debugging, though, give me a few minutes.

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