Cache, Create, Reference Remote Events/Functions

This resource is a very simple but effective way of using remote events/functions efficiently.

Note: There’s many different networking resources out there and this isn’t one of them, just basic usage of remotes

Resource:
EventModule.rbxm (1.4 KB)

Setup:
Place module in Replicated Storage
(Done!)

Usage:

-- Client
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local EventModule = require(ReplicatedStorage.EventModule) -- Can be anywhere in Replicated
local MyRemoteEvent: RemoteEvent = EventModule.Event("MyEventName") -- Name of event

MyRemoteEvent:FireServer()
-- Server
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local EventModule = require(ReplicatedStorage.EventModule) -- Can be anywhere in Replicated
local MyRemoteEvent: RemoteEvent = EventModule.Event("MyEventName") -- Name of event

MyRemoteEvent.OnServerEvent:Connect(function(Player)
-- Code
end)

If you want to have it be a Remote Function, just add “Invoke” to the name of the remote.

local MyRemoteFunc = EventModule.Event("MyEventNameInvoke"):: RemoteFunction -- Name of event
MyRemoteFunc:InvokeServer()
local MyRemoteFunc = EventModule.Event("MyEventNameInvoke"):: RemoteFunction
MyRemoteFunc.OnServerInvoke = function(Player)
-- code
end

– Why use this module?

– Organization: It’s cleaner
– Efficiency: Remote’s are cached in a reference table making it slightly better on performance
– Ease of use: imo it’s much easier to call a module and have all your remotes at your finger tips.

i’m having slightly similar approach honestly, so this use case real works i’d say

2 Likes