Requiring modules without writing the path

Hello! I have been trying to require a module without writing their paths but there are very limited posts about this and none of the solutions worked.

I was wondering, how can you require a module inside of a module script without writing the path?

Thanks in advance!

You can require them without a path if you have published them to roblox, use: require(assetID)

1 Like

I’ll try that solution, thanks for replying!

1 Like

Unfortunately module scripts cannot be required with assetID’s by the client. (ROBLOX WHY)

Hmm you can send a remote event to the server to require the module and place it in replicated storage perhaps?

Why do you want to achieve this in the first place?

1 Like

I am trying to make programs run by another module script called “Run”. Basically when requested it will open the given program and run the module script that operates that program.

The module is already inside of the game, I just need to require it without giving the path that leads to the module.

Do you think I could try to send a signal to the server via a remote event, and then return the information about the module script by using “return” thing?

Sounds more like you want to require by a dynamic path. Are these “programs” stored in the same location? If so, you could do something like this:

local Programs = game:GetService("ReplicatedStorage")

local function requireByName(Name)
    local module = require(Programs[Name])
    return module
end

--`require`'s the module `ReplicatedStorage.Program1`
print(requireByPath("Program1"))

These programs are not stored in the same location. Not all of them atleast… here, take a look.
image

Hm, are the Values acting as shortcuts? Are they Object Values or String Values?

Also could be useful to see the Run script to figure out how you want to load the modules

The values inside of Shortcuts are objectvalues but are not assigned to anything. The “Program” values inside of the objectvalues are however assigned to their respective program. Running the program works fine. Im attempting to make like the “error” thing that is run by the Run module in case the program is trying to give feedback in case something doesnt go succesfully or it crashes.

Template btw:

local program = {}
local run = game.ReplicatedFirst.Returner.Module:FireServer(113658183973815)
local app
--fired once the program has been opened
function program.run(program)
	app = program
	--code here.
end
--fires every frame
function program.update()
	
end
--fires when the program has been terminated or closed
function program.terminate()
	--potentially do run.error()
end


return program

If you can’t require the Run module from inside Programs, then maybe you can instead pass it through the .terminate function?

--fires when the program has been terminated or closed
function program.terminate(run)
	run.error()
end

Hmmm I didn’t think of that, it seems like a good idea

Hey, that worked! I didn’t need to require it without the path. Thanks, but if you don’t mind trying… maybe write the code that answers the title of this post so people who come here don’t leave dissapointed?

I’m not sure what you are referring to, this Forum is not for getting people to write code for you. The code I gave was to make my suggestion as clear as possible. You can help other people with the same issue, by marking my most helpful reply as the “Solution”, which adds a link to your original post that other readers with the same issue can see, which takes them to my reply.

Also, your issue was not very clear initially - You need to provide more context to your problem when you ask for help. If you had given the template Program up-front, then I wouldn’t have had to ask any questions and you could have gotten better suggestions from other people.

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