I am trying to figure out how to detect if a module script was required or if its functions were called without directly checking in each function
This is for a module I am working on and in certain aspects, some functions will not work on client and certain aspects will not work on the server.
2 Likes
You can use the RunService
to check if the module script is being ran from the client or the server then you can use this to disable certain functions.
References:
2 Likes
yea I know but like then I would need to check inside every new function I make. I am all about making things easier so I was wondering if there would be a way to check inside every function automatically if that makes sense
An alternative would be to have 2 different module scripts, one designated for functions you want the client to access and the other for server functions. You could then parent the Server Module to a service that the server can only access for example ServerScriptService
and the client one could go in ReplicatedStorage
.
this could work, but it sounds like a little more work honestly. But again is there a metamethod you know of that fires whenever a function is called from the module maybe I can use that to sort whether it should be called on the client or server. If there isnt then I will just do what you said
I mean you could do my first idea but in a function method. It wouldn’t be hard to add. Example:
function get()
local RunService = game:GetService("RunService")
if RunService:IsServer() then
return "Server"
elseif RunService:IsClient() then
return "Client"
end
end
if get() == "Client" then return end -- Blocks clients from using the function
4 Likes
Thats not rely what I meant but thanks anyways
1 Like
Sorry about that, I haven’t quite wrapped my head around metamethods yet. Anyways happy scripting!