Get the resource here.
Roblox does not provide a way to send functions from the server to run on the client, and for good reason. Although this safety precaution is necessary it makes it time consuming for those of us who don’t want to spend time creating and connecting numerous remote events every time we want to run some code. Code gets cluttered very fast, or perhaps that’s just me?
Some people prefer to load scripts onto the client and enable them, some prefer to use remote events. I wanted to retain the ease of not needing to connect remote event logic while also keeping existing remote logic decluttered.
Now you may be asking, Sal, remote events don’t take that long to connect, this isn’t necessary?
And you are absolutely right, but I’m just lazy and stubborn! HOWEVER, this resource also allows optional yielding until code on all the clients has completely successfully before returning. Niche use case but I find it helpful pretty often.
Soon I will add returning data from your local module functions back to where you initiated the code to be run from the server, this should make it so you rarely never need to create remote events and write remote event logic for simple tasks.
To get started place the Initialize
script in StarterPlayer > StarterPlayerScripts & place the RunClient module in ReplicatedStorage.
Require the module:
local RunClient = require(game:GetService("ReplicatedStorage"):WaitForChild("RunClient"))
Use the .runFunction()
method of the module.
RunClient.runFunction(module, players: {Player}?, yield: number?): boolean?
The module
parameter is the module on the client you would like to run, this module should return a function to be run, like so:
return function()
-- Code here
end
The optional players
parameter is a table of players whose clients you would like the module to run on, if you pass this as nil the module will run on all clients, equivalent to passing game:GetService("Players"):GetChildren()
.
The optional yield
parameter is a number telling the method how long it should yield and wait to here back from every client before returning. If you pass this as nil
then the method will not yield at all and will return true immediately, if all clients have run the function before the elapsed time has run out then the function will return true
, otherwise if any client fails to return from running the function in time then method will return false
.
Let me know if this helps you make remote connections faster and if there are any features you’d like to see!