Can't add values to module table via function?

I’ve been learning to use module loaders, and when Init function fires, the values I’m trying to add into the HumanoidEvents table are only added once. Once the player dies, the table is empty again? Is this the correct way to go about this system?

local clientModuleLoader = require(script.Parent.Parent.clientModuleLoader)

local humanoidEvents = {}

function humanoidEvents.Init()
	humanoidEvents["serviceLibrary"] = clientModuleLoader.GetModule("serviceLibrary")
	humanoidEvents.Player = humanoidEvents.serviceLibrary.playerService.LocalPlayer
	humanoidEvents.Character = humanoidEvents.Player.CharacterAdded:Wait()
	humanoidEvents.Character.Humanoid.Died:Connect(function()
		print(humanoidEvents.Character.Name.." has died!")
	end)
end

return humanoidEvents

Why would you need that?

More so why do you need init function if all content inside module script runs automatically once upon requiring?

--Initiate stuff here, no need for any dumb function


return

I still dont understand why yall people wont just make a separate script for that purpose.

And even if you want otherwise why wont you straight up return function?

return function():()

end

‘humanoidEvents’ should be initialised every single time a player’s character dies & respawns, as any prior old references would be outdated and would refer to a nil value. Yes, it only gets added once, because there seems to be no piece of code in that module that even updates the references.

There’s two ways to go about it:

A. Bind the client’s CharacterAdded event within that module script and update each relevant variable’s references. e.g:

humanoidEvents.Player.CharacterAdded:Connect(function(character)
    humanoidEvents.Character = character
    -- bind the humanoid Died event here again
end)

I also recommend you do :Once instead of :Connect as the event only needs to fire once and it’s better for avoiding memory leaks as much as possible.

B. Organize your respective modules into a folder; and said folder should all be re-initialised every time the client’s CharacterAdded event is triggered.

Heavily dependent on the kind of game they’re developing. In a lot of cases, a modular framework and workflow makes things a lot easier and more optimised. Cleaner code is another benefit.

It doesn’t optimize anything post-initiation.
Thread becomes dead once it stops yielding and reaches end of the code making this completelly pointless and more so pretty sure calling script dirrectly would be more optimized becouse it doesn’t have any overhead that module script could have
Regardless, both store bytecode and operate mostly the same.
Unless you want the process of initiation to yield the main script don’t go for it at all; don’t even think twice, since integrating it into Parallel Luau would be potentially harder.
Also its not Modular framework.
Modular framework is the ability to integrate code into a codebase seamlessly without having to restructure any logic.
It has nothing to do with module scripts specifically.
Not trying to sound rude or anything I’m just operating purely on logic and want others to do so instead of being brainwashed by buzzwords.

Regular script already could be a modular framework for example:
Making all parts with tag “KillBrick” killing any humanoid upon contact
that a modular framework example
Using modulescript for yielding untill stuff is initiated is not an example of modular framework

Most of the time pure “modularity” is bad
For example if your game needs damage hit to be wrapped in function for kills assists but your modular kill part provides no information of that is an example why pure modularity is bad
Semi modularity: etc requiring very tiny edit to integrate codebase on other hand is great