Here I am publishing my ModuleScript called “SafeFunctions”, showing what its do and more!
SafeFunctions is a ModuleScript created to offer a safe communication between Clients and Server, simulating a “new version” of a RemoteFunction. Generally we always avoid use the “InvokeClient” method, but when working with this module, it is not more a possible game-breaker!
This ModuleScript uses a RemoteEvent (internally called of “DataTransfer”) to send data between clients and the server. For example,if the server invokes a client, the server-side part of module will send a signal to client-side part of module with the ‘name’ of a “pseudo-RemoteFunction” and some parameters (it works as a “InvokeClient”); The client must bind a function in client-side part of module, and when client receive the signal from server, its will search for a binded function with the ‘name’ parameter, if it exists then its call the function and send a signal to server-side of module with parameters (which will be interpreted as a “return” from client-side); At end, the “return” from client is returned to the caller of the “InvokeClient” script.
local SafeFunctions = require(game:GetService("ReplicatedStorage").SafeFunctions) game.Players.PlayerAdded:Connect(function(Player) local ClientAnswer = SafeFunctions:InvokeClient(Player, "Hello") print(string.format("%s said: %s", Player.Name, ClientAnswer)) end)
local SafeFunctions = require(game:GetService("ReplicatedStorage").SafeFunctions) SafeFunctions:BindToInvokeClient("Hello", function() return "Hello server!" end)
(These examples can be found inside the module when you insert it in your game)
I know it is for a very specific use, but I think that it can help at development of a greater system/framework
Please report any problem with this module, and feel free to suggest anything to improve the module. All tips are well-come!