How do I check if a module script is coming from the server or the client?
I need this to make sure an API I’m developing doesn’t get used by the client.
2 Likes
At this point just leave it in ServerScriptService so clients won’t be able to access it?
1 Like
Fair point.
I was going to put it in Replicated Storage, but I’ll see what I do now.
You could also use
RunService:IsClient()
if you want to keep it in ReplicatedStorage.
13 Likes
You can do script.ClassName to see if it is a LocalScript or a ServerScript before using the Modulescript and then send it as an argument.
--localscript
local Module = game:GetService("ReplicatedStorage").Module
if script.ClassName == "LocalScript" then
--Module.doSomething(script.ClassName)
end
--Modulescript
local module = {}
function module.doSomething(className)
if className == "LocalScript" then
return
end
--code
end
return module
(Don’t use this, look at comment below)
Hello from the future, please do not use this method that I have given. I was ignorant about a much better way of approaching this problem. Here is the solution:
local RS = game:GetService("RunService")
local module = {}
function module.doSomething(something)
if RS:IsClient() then return end
--code in this function can never be run on the client
end
return module