So I made this plugin to aid me in constructing nodes for a system I’m working on, and it basically clones its own module-script and then pastes it on my ServerScriptService so that I can utilize it - if I use my output bar or something, I can actually yield variables attached to this module, but for some reason it just returns nil when I hit Play.
Any reasons why this happens? Anyone have any suggestions on how to get the script to give me this module?
We need something to work with before we can give you any answer. At least some information about what the module should return and a portion of the code.
So basically, my plugin’s code stores entities of this form
local Database = {
["1"] = {
Position = Vector3.new(...),
ID = ...,
...
},
...
}
When I compile the module, it writes Database to another module script that I actually have in ServerScriptService
The issue is that when I compile, I can actually get stuff about Database and its relevant variables using the output bar but it yields nil and what-not when I actually try testing
You said that you can get the data with the output bar, but not the way you do it. As far as I understand, your plugin writes over a ModuleScript’s source, which might be causing issues with the way modules cache their output.
Are you using the server view when you attempt to require the module? When you start a session, your command bar is client-sided, so you must change to the server.
Another point to make is that the command bar runs on a separate VM to regular scripts, so it’s treated as an individual machine. If your contents are input from a plugin or regular script, the command bar will not be able to see them. The same thing happens with the Lua Chat System: try fetching a list of speakers, it’ll be empty.
If you want to be able to test your code, you will need to set up a unit test using a game script and not the command bar. You can do this by writing code in ServerStorage in a script and then moving it to ServerScriptService where it will execute.
Going to need far more information and code samples to help you here if what I said doesn’t answer your question. You have me confused and lost and there isn’t much explanation to your issue either that I can understand.
local Nodes = require(script.Nodes)
local function Compile_Script()
local Paths = require(game.ServerScriptService.Manager.Path_Module)
Paths.Nodes = Nodes.Nodes
Paths.Max = Nodes.Max
end
Nodes.Nodes is the database structure I talked about
That would. So let’s redefine the problem… you’re supposedly getting nil back during test, but what are the circumstances? What is returning nil? How is it called? Where is it called? What view is active at the time? Try explaining the problem in more depth.
→ I just test by hitting the Play button in Studio
→ Whenever I refer to some member or aspect of Path_Module that I write to it by my plugin, all I get is nil - this includes Nodes and Max from my code snippet
→ I call for the Nodes and Max by just using require(...Path_Module)
→ I call for Nodes and Max in a server script held in ServerScriptService - this is also where Path_Module is actually held
→ I’ve tried it out on both Client view and Server view
I have a print in the code that calls it so I can see if the stuff is nil or not - in Client view, the server script that actually asks Path_Module for what I wrote to it just recieves and prints nil
Same thing in Server view - it just prints nil irrespective of how I try getting Path_Module’s contents
Scripts, LocalScripts and the command bar can’t see what a plugin writes to a script if I recall correctly. The plugin gets it’s own copy of a module on require and other scripts can’t see the changes made. Only cause I can think of.
Where and when is Compile_Script ran? If your plugin is meant to do this work pre-compile time (in Studio), you will need to write to ModuleScript.Source by converting your modules into strings and going from there, rather than requiring both modules and placing data through standard convention.
The plugin is meant to do all that before I actually run the game - the compiled module is meant to be referred to later on by the other scripts in the system
I’ll definitely check out this source editing via strings - thanks!
Just a warning that working with sources can be tedious and annoying. If it’s at all possible, try to avoid working with two modules and work with only one. Your plugin can hold temporary data in some form and when it compiles to a script, it writes out the data in Source accordingly.
I’m not familiar with this kind of writing and I don’t have a use for it either, but I’m at least aware of the mess it could rouse.