hello I am trying to run code in a module script without calling anything:
local module = {}
print("hello world") -- never runs
return module
as you can see, it does not run. How do I get it to run without having to call it?
Why do this?
I want to run code alongside module functions that can be called. The module functions can affect the behavior of the code.
You can’t. ModuleScripts do not run unless called
Edit: What do you mean by ‘called’?
you gave a solution that used a word you didnt know? how do you not know what called means as a programmer
silver4804
(silver4804)
February 10, 2024, 2:59am
4
local module = {}
function module:run()
print("hello world")
end
return module
script
local module = require(modulelocation)
module:run()
The module script runs client sided code only. I guess I could call it from the local script but its stupid localscripts dont work in workspace because I want to organize my modules rather than having junk everywehre
silver4804
(silver4804)
February 10, 2024, 3:00am
6
then put it in a local script…
char limit
Here’s an example:
return function()
print("hello world")
local module = {}
return module
end
silver4804
(silver4804)
February 10, 2024, 3:02am
8
what does your module even do?
I know what ‘called’ means. I was asking what you meant in the context of the question since you mentioned functions.
Anyway, were you asking if you can run code within a ModuleScript without calling a specific function in the ModuleScript? If so, just require a ModuleScript normally; there’s nothing additional you need to do
I want everything to be inside of the modules folder inside workspace and local scripts dont run in workspace but this is a client sided module
if I put a local script to call the module, it wont run in workspace.
silver4804
(silver4804)
February 10, 2024, 3:05am
11
then put the local script inside where it does run, StarterGui works
this is messy and unorganized tho. Perhaps I will make a script that unloads a local script into starterGUI
Module scripts I’m pretty sure can’t run without being required
You’re best bet is something like this:
return function()
print("hello world")
local module = {}
return module
end
You can create a Script and set its RunContext to Client to run a LocalScript in workspace
silver4804
(silver4804)
February 10, 2024, 3:06am
15
dude what are you even trying to do i really cant help you if you dont give any context to what youre trying to do
You’re not helping, stop asking for context and solve the actual problem
setting the runcontext to client literally just chanegs it to a local script which dont run in workspace lol
silver4804
(silver4804)
February 10, 2024, 3:08am
18
he said it doesnt run in workspace told him put it in StarterGui and says thats messy…
Problem: Want to run code in modulescript
Solution: Ask for context instead of trying to solve the problem
I don’t blame him. This is looking like an XY problem.
It’s such a redundant use case — it goes against the very principle of a ModuleScript.