Is this type of module script safe from Client

So this is a module script that I came up with.
This module script is to be put in ReplicatedStorage where both the Client and Server can access it.
Here it is:

local RunService = game:GetService("RunService")

local module = {}
module.Server = {}
module.Client = {}

function module.Server:foo()
    return "foo"
end

function module.Client:foo()
    return module.Server:foo()
end

if RunService:IsServer() then
	return module.Server
elseif RunService:IsClient() then
	return module.Client
end

Don’t question the purpose. I just want to know if this is safe from exploiters.

When a module is imported for the first time the result gets cached so that subsequent calls return the cached result. If the server and client both require a module script they each get their own results. The client doesn’t get the result that was cached on the server. It behaves as if they were separate computers requiring separate module scripts.
You can test this by having both the server and client script do print(module.foo). The printed memory addresses should be different, since one was compiled for the server and another for the client.
If you want the client to access or change a variable stored on the server’s module script table, like always you would need to cross that boundary with a remote function or event.

2 Likes