Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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.

5 comments

0

Thanks! I simply knew there was a single function for what I wanted to do.

1

You might run into issues with Studio. I had to work around that one for Studio only.

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!

1

It's in the link for how Valkyrie does it. I'll put it into the answer for ease.

0

Thanks again!

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.

1 comment

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.