-
What do you want to achieve?
I want to make a module script that both the client and the server can require and run their own functions from that module. But if there’s a variable that both of them use, for example an event, they can have it at the top without having to make 2 different scripts. -
What is the issue?
I’m not sure if doing aRunService:IsServer()
is reliable to protect the server’s function from a client. -
What solutions have you tried so far?
I thought about making a different ModuleScript inside the server storage, but I’ll have to require 2 modules and type down the same variables again.
…
Basically, I’m working on a custom weapon kit (Which I’m not 100% sure I’ll release), and I want it to work like that:
- The client detects when a new tool object has been added into the backpack or the character.
- The client will fire the server and the server will find a module script that has the same name as the player’s tool inside the replicated storage.
- If found, the server will run the server function, return the module, and the client will run the local function.
The module looks something like this:
return function(Tool)
--// Services //--
local Services = {
Run = game:GetService("RunService")
}
--// Variables //--
--// Events
local Fold_ToolEvents = script.Events
local Event_Hit = Fold_ToolEvents.Hit
--// Functions //--
return {
Local = function()
print("Local!")
end,
Server = function()
if Services.Run:IsServer() then
print("Server!")
else
print("Cannot run server function from the client.")
end
end,
}
end
I’m sure there’s a simple answer for that, thanks for reading