Library Module Script not working

Hello DevForum!
Today I’m stucked on my game on the same error. Basically, I’m doing a Library Module, where Instance, Modules and more are storaged there.

Here’s an example of what’s the Library Module:

local Library = {
	ReplicatedStorage = game:GetService("ReplicatedStorage");
	Players = game:GetService("Players");
	RunService = game:GetService("RunService");
	TweenService = game:GetService("TweenService");
	Lighting = game:GetService("Lighting");
	BadgeService = game:GetService("BadgeService");
	MarketplaceService = game:GetService("MarketplaceService");
	Workspace = game:GetService("Workspace");
	StarterGui = game:GetService("StarterGui");
	TeleportService = game:GetService("TeleportService");
	UserInputService = game:GetService("UserInputService");
	Chat = game:GetService("Chat");
	MessagingService = game:GetService("MessagingService");
	LogService = game:GetService("LogService");
	DataStoreService = game:GetService("DataStoreService");

	addLeaderstats = script:WaitForChild("LeaderstatsSystem"); --Module
	gameIntro = script:WaitForChild("gameIntro"); --Module

return Library

Let’s imagine a Local Script want to have access to the gameIntro by using the Library. However, here’s the thing: when I access the module script by its Asset Id, I know that Local Scripts can’t have access to require(Asset Id of the Module), so for that I’ve made that it calls a Remote Function which returns the Module. Here’s what I mean:

-- Local Script which tries to get access to the Library by using the module script
	local Table = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvents"):WaitForChild("getLibrary"):InvokeServer()
	return Table
-- The Script that returns the table.
	game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvents"):WaitForChild("getLibrary")..OnServerInvoke = function()
	return require(Asset Id of the Module here)
end

But everytime a local script tries to get access to the Library by using the Remote Function, it doesn’t return the table for some reason.

Anything helps, thank you! :slight_smile:

It’s this part I’d assume

	return require(Asset Id of the Module here)

And I don’t want to tell you why because the solution is simple if you knew how to script.

1 Like

if you mean the part that says “Asset Id of the Module here” it’s because I’m not going to add the Asset Id of the Module Script on the DevForum. If it is something else, let me know :smiley:

Hello there,

First of all in your module, you’re returning the Library table without ever closing it. I’m not sure if that’s just an error in typing the post, regardless, important to be aware of.

local Library = {
	ReplicatedStorage = game:GetService("ReplicatedStorage");
	Players = game:GetService("Players");
	RunService = game:GetService("RunService");
	TweenService = game:GetService("TweenService");
	Lighting = game:GetService("Lighting");
	BadgeService = game:GetService("BadgeService");
	MarketplaceService = game:GetService("MarketplaceService");
	Workspace = game:GetService("Workspace");
	StarterGui = game:GetService("StarterGui");
	TeleportService = game:GetService("TeleportService");
	UserInputService = game:GetService("UserInputService");
	Chat = game:GetService("Chat");
	MessagingService = game:GetService("MessagingService");
	LogService = game:GetService("LogService");
	DataStoreService = game:GetService("DataStoreService");

	addLeaderstats = script:WaitForChild("LeaderstatsSystem"); --Module
	gameIntro = script:WaitForChild("gameIntro"); --Module
	
}

return Library

Additionally, I don’t see why you wouldn’t want to require() the AssetId once and then returning the preloaded asset upon OnServerInvoke instead of requiring it individually for each client.

-- ServerScript

local ReplicatedStorage, RemoteEvents = game:GetService("ReplicatedStorage")
local RemoteEvents = ReplicatedStorage:WaitForChild("RemoteEvents")

local LibraryModule = require(00000000)

RemoteEvents["getLibrary"].OnServerInvoke = function(plr)
	if not LibraryModule then return end
	return LibraryModule
end
-- LocalScript

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvents = ReplicatedStorage:WaitForChild("RemoteEvents")

local Library = RemoteEvents["getLibrary"]:InvokeServer()

local Players
if Library then
	Players = Library["Players"]
end

Hope that helps. Good luck.

1 Like

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