Function not connecting to signal with custom module loader

I have a custom module loader that runs fine and does what its supposed to but for some reason is blocking my Players.PlayerAdded connection. I just need it to init the player from my module.

Here is the code. The output right now is 1 but not hello

task.wait()
shared.ModulesLoaded:Wait()
--Service
local Players = game:GetService("Players")
local PlayerModule = shared.Get("Player")

local function OnJoined(Player)
	print("hello")
	PlayerModule.new(Player)
end
print("1")
Players.PlayerAdded:Connect(OnJoined)

Here is the module loader:

local Signal = require(script.Signal)
shared.ModulesLoaded = Signal.new()

local ModuleLoader = {}
local CachedModules = {}

--Loader Functions
function ModuleLoader.Get(moduleName: string)
	return CachedModules[moduleName]
end

function ModuleLoader._Init(modules: {ModuleScript})
	for _, module in modules do
		local newModule = require(module)
		CachedModules[newModule.Name] = newModule
	end
end

function ModuleLoader._Start()
	for _, module in CachedModules do
		if module.Start then
			task.spawn(module.Start)
		end
	end
end

shared.Get = ModuleLoader.Get

return ModuleLoader

NOTES:

  • Will print if anything related to the module is taken out of the script.
  • When putting the connection in a variable, conn.Connected = true
  • Im using Fast Signal Immediate for my custom signals
  • Is under another script under server script service. But when placing the the problem script in server script service. still doesnt fix anything

Seems to me the Player Added functions runs after the player has already joined the game due to the delays above, so you’d have to process all players currently in the game after that line as well

for _, player in ipairs(Players:GetPlayers()) do
    OnJoined(player)
end

race condition error on studio you sometimes join the server before the scripts finish loading leading to playeradded not firing, just add a IsStudio() check hard coded

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