For some reason my module loader just doesn’t start the MouseObject module like I even added a descendence event but it still just will decide randomly if to start the module, it initializes it but like it DOESNT START whyyyy.
My workspace: (clientLoader is the clientside module loader)
clientLoader:
local require = require
local modules = {} --Required Modules
local initializedIndexes = {} --List of Initialized Modules
local startedIndexes = {} --List of Currently Running Modules
--DIRECTORIES
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PlayerScripts = game:GetService("StarterPlayer"):WaitForChild("StarterPlayerScripts")
local CharacterScripts = game:GetService("StarterPlayer"):WaitForChild("StarterCharacterScripts")
local directories = {ReplicatedStorage.Modules, PlayerScripts.Modules}
function setup(dirs : {Instance})
for _, dir in dirs do
for _, mod in ipairs(dir:GetDescendants()) do
if mod:IsA("ModuleScript") then
local req = require(mod)
req._name = mod.Name
req._priority = math.clamp(req._priority or 10,1,10)
table.insert(modules,req)
print("----Module ["..mod.Name.."] required!---- (Priority :"..req._priority..")")
end
end
dir.DescendantAdded:Connect(function(mod: Instance)
print(mod.Name)
if mod:IsA("ModuleScript") then
local req = require(mod)
req._name = mod.Name
req._priority = math.clamp(req._priority or 10,1,10)
table.insert(modules,req)
print("----Module ["..mod.Name.."] required!---- (Priority :"..req._priority..")")
if mod.Init and not table.find(initializedIndexes, i) then --If the module has the Init function and isn't already initialized
table.insert(initializedIndexes, i)
mod.Init()
print("----Module ["..mod._name.."] initialized!---- (Priority :"..mod._priority..")")
end
if mod.Start and not table.find(startedIndexes, i) then --If the module has the Start function and isn't already running
table.insert(startedIndexes, i)
mod.Start()
print("----Module ["..mod._name.."] started!---- (Priority :"..mod._priority..")")
end
end
end)
end
table.sort(modules, function(m0, m1): boolean --Sorts based on priority 1st-10th
return m0._priority < m1._priority
end)
print(modules)
end
function initializeModules()
for i, mod in ipairs(modules) do
if mod.Init and not table.find(initializedIndexes, i) then --If the module has the Init function and isn't already initialized
table.insert(initializedIndexes, i)
mod.Init()
print("----Module ["..mod._name.."] initialized!---- (Priority :"..mod._priority..")")
end
end
end
function startUp()
print(modules)
for i, mod in ipairs(modules) do
if mod.Start and not table.find(startedIndexes, i) then --If the module has the Start function and isn't already running
table.insert(startedIndexes, i)
mod.Start()
print("----Module ["..mod._name.."] started!---- (Priority :"..mod._priority..")")
end
end
end
setup(directories)
initializeModules()
startUp()
Example of it working:
Example of it buggin: (Not starting mouse object)
It has both the start function and init but the start function just randomly doesnt start.
local rGrabber = require(ReplicatedStorage.rGrabber)
local cGrabber = require(game:GetService("StarterPlayer"):WaitForChild("StarterPlayerScripts").cGrabber)
local cam
local character : Model
local mouseObject : Part
local mouseHit = require(cGrabber.grabModule("CustomMouseHit"))
function module.Init()
rGrabber.grabEvent("CharacterLoaded").OnClientEvent:Connect(function(charModel : Model)
character = charModel
cam = workspace.CurrentCamera
mouseObject = script.Mouse
mouseObject.Parent = workspace
end)
end
function module.Start()
RunService.PreRender:Connect(function(deltaTime: number)
local ray : RaycastResult = mouseHit.Hit({character,mouseObject},{"Roof"})
if ray then
mouseObject.Position = ray.Position
end
end)
end
return module
pls help me im begging