CS_Communicator (Client-Server Communicator)
An easy to use, object oriented approach to client-server communication.
Why use CS_Communicator?
As Roblox grows into a massive ever-evolving platform, security is an issue. FilteringEnabled is a (deprecated) property in Workspace that is automatically toggled as you start a new place, which is a big first step to combat malicious exploits in-game, blocking client changes to the server. New scripters are required to learn how to work with FilteringEnabled to disable experimental mode in their games- through remotes.
Remotes can be tedious to maintain especially when the game grows to be complex.
CS_Communicator aims to make client-server communication seamless and easy.
CS_Communicator installation/ usage:
Hereâs the GitHub code. Please familiarize yourself with the license (and very much appreciated if I can be credited somewhere in the game/description!)
Put this in a ModuleScript.
Examples:
-- Server script
local FE = require(path.to.module);
FE.hookUpClientRemotes {
clientTest = 'async'
};
local Listener = FE.listen('sync', 'serverTest', function(Player, Text)
print(Player.Name, Text);
return 'Test done!'
end);
wait(3)
FE.fireAllClients('clientTest', 123);
-- Local script
local FE = require(path.to.module);
print(FE.request('sync', 'Test Name', 'abc'))
FE.listen('async', 'clientTest', function(Arg)
print(Arg);
end)
-- Output
iiau abc (server)
Test done! (client)
123 (client)
API
* <String>Type is an Enum, with values 'sync' or 'async' FE.listen(<String> Type, <String> Name, <Function> Listener) return: <Communicator> > On the server, creates a new remote and listens to it. FE.request(<String> Type, <String> Name, <Variant> Args ...) return: nil (async), or returned arguments (sync) > Sends a request across client/server FE.hookUpClientRemotes(<Dictionary> Remotes) return: nil > Remotes must have this format: { ['Name'] = 'async'/'sync' ... } > Sets up remotes for the client to listen to. FE.waitForRemote(<String> Type, <String> Name, [Number: 10] Timeout) return: Remote instance if exist, or nil if surpassed timeout > Waits for given remote instance to exist for reference. FE.fireAllClients(<String> Name, <Variant> Args ...) return: nil > If a RemoteEvent is found with the given name and it's called on the server, fire all clients with given arguments <Communicator> :Destroy() > Destroys the communicator, sets the object to nil
For experienced programmers:
You can also add your own methods to this module and specialize it to your likings. Have fun