How to make custom event shared between client and server?

So I’m working on custom events similar to Roblox’s ones, and the biggest issue I have right now is thinking about how to make the events shared between the client and the server.

This is the logic I’m using with the events.

local connectionClass = require(...)

local eventClass = {}
eventClass.__index = eventClass

function eventClass:Connect(functionToConnect)
    local connection =
    self.connections[#self.connections+1] = connection

function eventClass:Fire()
   for i = 1,#self.connections do
       local v = self.connections[i]

return {
           new = function()
               self = setmetatable({}, eventClass)
               self.connections = {}
               return self

By “shared between the client and server” do you mean sending via Remote Functions?

If so, functions cannot be sent between the server and the client because they do not serialize. One workaround is putting the function in a module script which is referenced in the event connection instead.

So you know how .Touched can be used by both client and server? Thats what I’m trying to achieve, an event that can be connected both server and client and run the functions.

1 Like