I have a client-side ATM GUI, a server-side ATM Handler, and a (admittedly very long) ModuleScript called the BankSystemModule which work together to form part of a banking system.
Right now I’ve discovered that the handler doesn’t work because there are problems with the module script. The paths are all correct, and the right thing is being required, but the system doesn’t actually recognise all of the module script’s functions.
One of the functions for instance is ATMWithdrawal
The handler, however, doesn’t recognise there being any function in the modulescript whose name starts with “ATM”. Instead, it only recognises a seemingly random set of functions among the module script.
Does anyone have any idea as to what’s going on, and how I can fix it?
See also what I mean about the module being “very long”.
I’ve since created a new testing place and either deactivated or deleted everything un-necessary in the hope of isolating the problem but it’s not working.
Please bear with me as I’ve never done metatables before (and this is my first complex scripting project). I wrote a snippet to drop in just after BankSystem = {} as follows:
local metatableDebugSystemOn = true
if metatableDebugSystemOn == true then
setmetatable(BankSystem, {
__index = function(table, index)
print(table, index)
return rawget(table, index)
end,
__newindex = function(table, index)
print(table, index)
return rawget(table, index)
end,
})
end
But it gives me this error when I start a session in Studio:
There’s no apparent reason why it should do that, but it returns “nil”. The weird thing is that some functions are recognised by other scripts and others are not, for some inexplicable reason.
Failing the meaningful ability to analyse all that code, would dividing the script up and each script cross-referencing each other improve the situation in any meaningful way?
What exactly do you mean by “recognise”; are you talking about not getting up-to-date autocomplete in Studio’s code editor when you type “BankSystem.”, or do you mean that you actually get errors trying to call some functions in this module, but not others?
In effect both. Not only doesn’t it autocomplete the function (but does autocomplete some limited other functions in the same module script), but I’ve found that the server side handler functions just fine until elements of the modulescript are introduced. The simplified structure of the handler looks like this
Services, definitions etc.
local bankSystem = require(moduleScript)
Some utilities, including those that require functions from the module
Main function fired by an event
If I get rid of the snippets that require the modulescript, or that call functions from the modulescript, the handler works fine, (minus the fact that it doesn’t do anything meaningful since the functions involve the modulescript).
P.S. Subtotal Sorry I “replied” to you. I wanted to quote you at first but then I didn’t need to, I deleted the quote but I didn’t realise that it still tagged “replied”.
You can’t have circular dependency in requires. Like if the BankSystem module has require(PinManagerModule), the PinManagerModule can’t have require(BankSystem). You can’t have any cycles; if module A requires B and B requires C and C requires D, then D can’t require A, B, or C. You have this sort of problem somewhere in your code architecture, and you have to rethink things.
That would make sense, now I come to think about it, thanks!
I’ve set up some prints at various stages throughout the moduleScript and it seems to load a large part of it now (and the metatable works) but it’s still not working fully it seems. I’m starting to think that there are lots of separate snags (none of it has been meaningfully tested until now) here and there.
Edit/Update: This issue has been resolved but a new unrelated issue has come up.