local SNet = require(path.to.SNet).new()
local ExampleModule = require(path.to.ExampleModule)
-- SNet --
SNet:Rollup({
-- List of ModuleScripts goes here --
ExampleModule.Package()
})
SNet:Compose()
local ExampleModule = {}
ExampleModule.__index = ExampleModule
function ExampleModule.new()
local self = setmetatable({}, ExampleModule)
return self
end
function ExampleModule.Package()
return require(script.EmittableFunctions)
end
local EmittableFunctions = {
Server = {
Events = {
["TestServerEvent"] = function(player, ...) -- "TestServerEvent" will be known as the "eventName"
end
},
Callbacks = {
["TestServerCallback"] = function(player, ...)
return "Hello World"
end
},
},
Client = {
Events = {
["TestClientEvent"] = function(...)
end,
},
Callbacks = {
["TestClientCallback"] = function(...)
return "Hello World from Client!"
end,
}
},
Name = script.Parent.Name -- "This will be youir "hostName"
}
return EmittableFunctions
- SNet:EmitCallback(hostName: string, callbackName: string, ...)
- SNet:EmitEvent(hostName: string, eventName: string, ...)
- SNet:EmitClientEvent(player: Player, hostName: string, eventName: string, ...)
- SNet:EmitClientCallback(player: Player, hostName: string, eventName: string, ...)
- SNet:EmitAllClientEvent(hostName: string, eventName: string, ...)
So you don't have multiple server scripts doing RemoteEvent.OnServerEvent:Connect(function(player) end)
over and over again. Same thing with ClientSide events, it allows for better organization of your modules and logic. So instead of calling a (probably horribly named) remote event for a specific task, make a module that handles that task and other similar tasks, and when you need something done over the network, you can call methods that do it for you.