ModuleScript not recognizing function?

Hi,

So after I was finished reworking a Round System, I was trying to rewrite the Script that Handled the Code, but when I was getting to the Main Function that Handled the Game, The ModuleScript couldn’t seem to find the function, and in testing, it would return an error, which is odd as when I invoke the function inside the ModuleScript, it works just fine.

I made sure to check for any error’s, and tested with random ModuleScripts, and for some reason, I have the same issue with one of them not appearing, or “existing” according to the Script.

Why could this be happening? I’m getting every single function except this singular one randomly not existing anymore?

it may be because you might have called the function using . and defined it using : or wise versa(it may be the reason, not sure). If you share your script, we can help with that

I dont think you understand how OOP works (no offense), but no, I have checked the Operator, and thats not the Issue.

And, It happens with any ModuleScript, one function is just randomly missing from the table.

Can u provide example of the issue. Also did u make sure that u are not setting the function to nil somewhere.

Can you put the code (or just the function and module part of it) without the game handler?

Very plausible. Check if you are setting it to nil anywhere in the script, maybe a stray line of code you accidentally typed wrong?

Nope, Im able to access it within the Module, but not outside it, if you read my post.

Would be helpful if we could see what’s crisply going in behind the scenes.

1 Like

It happens to me with any ModuleScript.

I tested with making Test ModuleScript, making just random functions inside the table. And when I required it. One is just randomly gone, Even If im not doing anything to the function.

Its not that easy to explain or show, as for some reason my code is working just fine with nothing interrupting it, but not “existing” when I want to use it.
Its like this:

module.__index = module

function module:ex() -- function
    print(self.Number)
end

function module.new()
    local self = setmetatable({}, module)
    self.Number = 3
    return self
end

module.new():ex() -- works fine within the ModuleScript, works as normal and as intended

return module.new()
local mod = require(script.Parent)

mod:ex() -- does not appear, or fire at all

It doesnt appear to be setting the function to nil or anything, its just gone, even with a simple function.

This makes absolutely no sense to me as I put the module in and it… works just fine?
It both autofilled and and fired as expected so the only thing I can think of is that you required the wrong module or something.

I think I fixed the Issue, All I did was enable --!strict, and fix the warnings it provided, and that seemed to have it fixed it.

I was appearently using self incorrectly in some parts.

Nope, same Module.

What was really the problem with self ? Just asking to learn.

I’m not entirely sure how what I did that fixed it but:

The functions I was trying to Invoke wasnt using self, and those functions required self to function.
All I did was fix them, and them the function popped up, and started working again.

I also fixed some type errors, that may be the reason however.

1 Like

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