Alright. So there is this major issue on the local script where I can’t even require a module from the ReplicatedStorage as well when the ReplicatedStorage requires a module from the ServerScriptService when it is non-existence. Take a look at the three major codes below and see what we can change. Here are also the properties & Instances
Instances
A module from the ServerScriptService
A module from the ReplicatedStorage
A local script calling the module from the ReplicatedStorage
If you can’t access the container from a localscript, you can’t access it by routing through a modulescript. You can’t access any items in ServerScriptService with a localscript that were placed there by the server, if you place an item there on the client you can.
To achieve what you are currently doing, you should use a RemoteEvent/Function, it will have an error due to a client’s ping.
When using shared modules (modules that you need to use on both the client and the server), you always need to assume that you can only access things that the client has access to, i.e. nothing in ServerStorage or ServerScriptService. If you need to run a function on the server, and have a value returned from the server, consider using a RemoteFunction!
Eh. This isn’t necessarily true. If you change the values of some variables depending on the environment it’s being ran in, you can have a shared module easily that incorporates the server AND client. You shouldn’t need remotes and unnecessary traffic unless you really need cross-environment communication.
local RunService = game:GetService("RunService")
local IS_SERVER = RunService:IsServer()
local module = {}
module.Example1 = IS_SERVER and function(arg)
warn("s", arg)
end or function(arg)
warn("c", arg)
end
module.Example2 = function(first)
return IS_SERVER and function(second)
print(first, second)
end or function(second)
warn(first, second)
end
end
return module
--
local module = require("module")
module.Example1("foo") --> env_letter foo
module.Example2("foo")("bar") --> foo bar