Module script cant get a folder from server storage

I’m trying to make an import module where if i change a name of an object used in multiple script I don’t have to change all of them and only have to change in the module script but the module script cant find BindableEvent in ServerStorage when its there in it (the module is in ReplicatedStorage)

image_2023-09-09_110851583

The code:

local RS = game.ReplicatedStorage
local SS = game.ServerStorage

local GameModule = RS.GameModule
local GameMemory = RS.GameMemory
local BindableEvent = SS.BindableEvent
local VariableFolder = SS.Variable
local ScriptModule = script.Parent

Error:

BindableEvent is not a valid member of ServerStorage "ServerStorage"

If the module is required from a local script then it will error because ServerStorage doesn’t replicate to clients

add WaitForChild()

local RS = game.ReplicatedStorage
local SS = game.ServerStorage

local GameModule = RS.GameModule
local GameMemory = RS.GameMemory
local BindableEvent = SS:WaitForChild("BindableEvent")
local VariableFolder = SS.Variable
local ScriptModule = script.Parent

put ModuleScript into ServerScriptService and script

given the fact that its in replicatedstorage, you are most likely calling require() on the client

if you didnt know, requiring module scripts sets the current side as the requirer’s side

CLIENTSIDED scripts cannot access server-only services like ServerScriptService or in your case, ServerStorage

Let’s say this is a localscript:

local moduleScript = require(game:GetService("ReplicatedStorage"):WaitForChild("ModuleScript")
--module script is now clientsided

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