Injecting LocalScript into clients from server

I read up on the RunContext stuff you mentioned and tried it out. It worked just like that™!

For whomever wants to know how this works, here is a short summary:

  1. Create a normal Script (not a LocalScript) called MyLocalScript. It does not matter where it is parented, as long as it is accessible from your main server script.
  2. Set the RunContext property of MyLocalScript to Client and the Enabled to false in the Roblox Studio Property editor.
  3. From your main Script, when you feel like running MyLocalScript for a player, clone it and parent the clone to anywhere inside the player and set Enabled = true on the clone.
  4. At this pointMyLocalScript will run like a normal LocalScript would for that player, and it will run until the player exits.

Important notes:

  1. It needs to be a normal Script and not a LocalScript. By setting the RunContext to “Client” it stops behaving like a server side script and starts working like a LocalScript.
  2. It will NOT play nice with the “starter folders”, so please don’t try to put it in places like StarterPlayerScripts etc. (it might be started twice which creates trouble).
  3. The script will not really be copied, but rather the bytecode compiled on the server will be streamed to the client which actually provides some extra security/elegance/speed benefits.

For more details please see this article, this property reference and this enum reference.