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.
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.
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
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.
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