Module script help

here is an example of what my problem is about

local module = {}

module.test1 = function()
    return 5
end

module.test2 = function()
    return 5 + module.test1()
end

return module

how would I make it only return 5 in test1 if test2 was called
since you could simply call test1 in any script
maybe im thinking too hard but im guessing something related to if statements would work

1 Like

You are adding 5 to a function. You’ll instead want to call that function by doing module.test1().

Edit: Oops sorry I didn’t understand the question you were asking earlier.

not the point I can simply edit my post

This is the wrong category, you should go to #help-and-feedback:scripting-support

forgot to change while typing it up sorry bout that

If you want functionality that’s global to all scripts when they require the module, I would recommend using global variables. You could keep a variable (something like _G.test2Called) that would keep track of if test2 was called. This global variable could be checked in test1 and handled from there.

module.test1 = function()
    if _G.test2Called then
        return 5
    end
end

module.test2 = function()
    _G.test2Called = true
    -- do other stuff here
end

isn’t _G bad practice tho?
I thought it had problems with it

I’m not sure there are any options other than globals (_G and shared).

besides with your example you have shown you can easily change the global variable in another script
which wouldn’t work at all

You could have a BoolValue that would keep track of this. Also, if you really, really don’t want to use globals, you could create some system using bindable events that would send over special keys that would verify their authenticity.

actually I have a more simple idea I can try instead

I made it work without _G or shared and nothing extra

I did smth simple