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:
- Create a normal
Script
(not aLocalScript
) called MyLocalScript. It does not matter where it is parented, as long as it is accessible from your main server script. - Set the
RunContext
property of MyLocalScript toClient
and theEnabled
tofalse
in the Roblox Studio Property editor. - 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 setEnabled
=true
on the clone. - At this pointMyLocalScript will run like a normal LocalScript would for that player, and it will run until the player exits.
Important notes:
- It needs to be a normal
Script
and not aLocalScript
. By setting theRunContext
to “Client” it stops behaving like a server side script and starts working like aLocalScript
. - 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). - 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.