Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What's the best way to tell if you're running on the server or client?

Asked by 9 years ago

To do this, I used to use game:GetRemoteBuildMode(), but recently, I suspect that it has been changed to not report results correctly (it reports false for both sides now). So is there a now a real, non-hackish way to tell if you're running a script from the client or the server?

2 answers

Log in to vote
1
Answered by 9 years ago

Same way Valkyrie does.

local RunService = game:GetService("RunService");
if RunService:IsClient() then
  -- We're on a client woop woop meep meep
else
  -- Poo :c
end;

You may run into issues with Studio
To get around it, you can check if the script should be considered local.

local isLocal = RunService:IsStudio() and script:IsDescendantOf(game.Players) or RunService:IsClient();

"Why don't you just check if it's a LocalScript?"
It's from Valkyrie, which uses ModuleScripts inside of the Players. You'll be able to implement your own context-aware check.

0
Thanks! I simply knew there was a single function for what I wanted to do. iconmaster 301 — 9y
1
You might run into issues with Studio. I had to work around that one for Studio only. User#6546 35 — 9y
0
Thanks for letting me know. I have a similar, hackish function to tell me if I'm playing Solo or not... I'd love to see your version, however! iconmaster 301 — 9y
1
It's in the link for how Valkyrie does it. I'll put it into the answer for ease. User#6546 35 — 9y
0
Thanks again! iconmaster 301 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

If you're using a local script, then it's the client. Anything that local script does will become transferred to the server so everyone else may see what occurred on that client, with the exception of FilteringEnabled which stops the transfer of what a local script does on one client to the server.

A Script will be ran on the server, anything on the server ends up to be transferred to the client. You should know when something is on either client or server, not really sure if there Is a way to check or why one would need to.

0
Not helpful, I'm afraid. I'm making a ModuleScript that can be activated from LocalScripts or Scripts, and needs to tell the difference. iconmaster 301 — 9y

Answer this question