SafeInvoke module for remote functions

Resource

SafeInvoke - Creator Store (roblox.com)

I made this module for managing my remote functions without deviating too much from Roblox’s vanilla remote functions. The only two things I added was timeout, and an error handler. I still do not know why Roblox has not added these yet but here I am making this module for my project. If there are any areas that could be improved, please do tell me in the replies. This is assuming that you already know how to use Remote Functions. Although, there are other resources out there that are much better than mine, I just wanted to share this just in-case anybody finds it useful. :slight_smile:

Usage

If you already have a remote function variable then just wrap it with SafeInvoke.new()

local SafeInvoke = require(SafeInvoke)
local remoteFunc = SafeInvoke.new(ReplicatedStorage.Events.RemoteFunction)

We can still hook a function to the OnServerInvoke or OnClientInvoke like how you would normally would.

remoteFunc.OnServerInvoke = function() end
remoteFunc.OnClientInvoke = function() end

There are two ways you can use this module to invoke.

  1. Using our variable reference.
local remoteFunc = SafeInvoke.new(RemoteFunction)
remoteFunc:InvokeServer()
remoteFunc:InvokeClient()
  1. By calling new and directly calling invoke.
SafeInvoke.new(RemoteFunction):InvokeServer()
SafeInvoke.new(RemoteFunction):InvokeClient()
2 Likes

Hey, this is honestly super cool I would apperciate it if there was like a way to add like ‘RateLimits’ or basically debounces which would help a lot

I did consider adding some sort of request limit where there would only be able to invoke up to say 5 requests in one remote function and any subsequential requests would just return nil. I decided against this as invokes usually doesn’t take too long unless your code errors or yields for long periods.

As for the debounces, you would just have to design your own system that schedules invokes as this module is to just give a few extra features to prevent infinite yields and errors forever bricking your code.

1 Like