Module Is Not Running But No Errors

Theres Absolutely No Errors But My Module Seems To Not Run. I’ve Done Module Loader And Manual From The Client.

--Create Table
local Module = setmetatable({}, {__index = function() --Returns Function On Attempted Indexing
	return "Invalid Index" --Return String On Invalid Indexing
end,})

--// Handles Input On The Client And Fires To Server Front-End

function Module.Input_Manager(Mouse : PlayerMouse) 
	Mouse.Button1Down:Connect(function() --//On Left Click Return Function
		
		local ReplicatedStorage = game:GetService("ReplicatedStorage") --//Get ReplicatedStorage
		local OnMouse = ReplicatedStorage["Events"]["OnMouse"] --//Get OnMouse Remote Event
		
		OnMouse:FireServer({"Base"}) --Returns Table Of Info For Server
	end)
end

--//OnMouse Remote Event Handler

function Module.OnServer()
	return warn("Test: Hello")
end

--// Initialize Every Function In The Module

function Module:Init()

	local ReplicatedStorage = game:GetService("ReplicatedStorage") --//Get ReplicatedStorage
	local OnMouse = ReplicatedStorage["Events"]["OnMouse"] --//Get OnMouse Remote Event
	
	local Players = game:GetService("Players")
	local Mouse = Players["LocalPlayer"]:GetMouse()

	
	Module:Input_Manager(Mouse) --//Passes In Clients Mouse Properties
	OnMouse.OnServerEvent:Connect(function() Module:OnServer() end) --// OnMouse Event Function
	
end

return Module --Return Module For Module Loader

1 Like

The reason your module isn’t running is because they don’t actually run on their own.
You need to use them in a separate script.
Something like this:

local Module = game:GetService('wherever is containing yo script).Module
Module:Init()

I am assuming that you know that you need to have a function to return an object if you are trying to make a module object rather than just a bunch of functions.

In addition to that, you can just keep those functions as local functions since you probably don’t need them individually.

I Used A Module Loader o Call The Init Yet Still Doesn’t Work

Oh yeah wrap the game:GetService in a require()

Obviously thats how you require a module

:man_shrugging:
I don’t know man, your code is weird. Just use the basic method of doing things.

Very late response but to anyone wondering, the correct way to call a module is as this:

require(game.ReplicatedStorage.exampleModule)

Change the brackets to contain a pathway to your module.

require(game:GetService(“Replicated storage”).Module) is the same as require(game.ReplicatedStorage.exampleModule). There are multiple “correct” ways to do a single operation.

That isn’t what I was correcting, in my response I was demonstrating how to use require(), not explorer hierarchy