ModuleScript recogize only Once per Join when running a ModuleScript

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? I want a ModuleScript to recognize all changes so I’m not lazy to rejoin again

  2. What is the issue? When I run a ModuleScript function, And I change the function and run it again, And it repeat a previous function

Example of what I mean

When I call a function named “Blah” in ModuleScript, It throws an error because it detects errors, Now I’ve fix it and it was correct, Now I run it again, It throws the same error, No matter how many times I am running, It throws the same error

require(workspace.Module).Blah()
Throws error
“Attempt to index nil with blah blah blah”
I fixing it and I run
require(workspace.Module).Blah()
Throws error
“Attempt to index nil with blah blah blah”

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub? Yes but I didn’t found it, If it already had then send me

  2. More

  • Everytime I got an error, I have to rejoin a Roblox Studio to run a new function and check
  • Everytime I rejoin, The issue isn’t disappear, But it let me call 1 function per join
  • Everytime I post, I am very afraid of getting my post flagged

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local module = {}

function module.blahblahblah(blah)
	--I won't show cuz secret
end

return module

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three (4) questions above, you should probably pick a different category.

Thanks for reading :slight_smile:

How is someone suppose to tell you why your function is erroring if they don’t know anything about the function :sweat_smile:

At least maybe include the error you’re getting?

When you run require(workspace.Module) for the first time it runs all the code and stores the single returned value (ex: module). If you’re getting an error like this it means that running the function causes a state change in the module table which causes the function to no longer work.

Impossible to tell you why without any clue as to what your code or the error is though. If your code is too secret for the forum honestly it’s a waste of other peoples’ time to try and help you with it.

1 Like
local module = {}

function module.AutoScrambleWord(word)
	if #word < 2 then
		return word
	end

	local characters = {}
	for char in word:gmatch(".") do
		table.insert(characters, char)
	end

	for i = #characters, 2, -1 do
		local j = math.random(i)
		characters[i], characters[j] = characters[j], characters[i]
	end
	
	return table.concat(characters)
end

return module

Plus I didn’t mean the error of a function, I meant why does MOduleScript recognize a function only Once per join

It’s just an example

And

Can you give me more information that contains that quote?

Are you testing the module in the cmd bar? It works the same way as it does for games in the command bar – if you call require it creates a single stored copy and doesn’t update it if you change the script. To make it update you need to cut and paste the module.

Say your module returns a table named module.

When you run require(TheModuleScript) for the first time, it runs all the code in your module until the return statement then saves the return value so it doesn’t need to run the whole module script again and returns the value it saved.


So if your module script is

local curTime = tick()
print("The time is "..string(curTime))

return curTime

And you do

local moduleScript = --[[ some code to get your module script ]]--

print(require(moduleScript))
print("Waiting 60 seconds!")
task.wait(60)
print(require(moduleScript))

It would output something like

The time is 12345.1234
12345.1234
Waiting 60 seconds!
12345.1234

Notice how despite the changes in time, it will always return the same value. It stores the return value and never runs the module script again no matter how many times you call require or if you change the module script’s code.

The time is 12345.1234 – printed only once b|c the module’s code only runs once ever
12345.1234
Waiting 60 seconds!
12345.1234 – the module’s return value is stored, so even though the time changes the module still returns the same time


Edit: On the same note as the command bar stuff, if you change a module script’s code during a play test it doesn’t matter if you require it again, it will still be the same value.

1 Like

YES, HOW DID YOU KNOW??? + It worked, Thanks

1 Like

I also was confused by the same problem a few years ago. Glad I could help!

1 Like

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