Server
local BufferNet = require(path.to.BufferNet2)
local net = BufferNet.new(game.ReplicatedStorage)
-- create your remotes here...
net.FinishInitilaztion()Client
local BufferNet = require(path.to.BufferNet2)
local net = BufferNet.new() -- yields until the server finishes initializationnet:CreateRemote("Event", "PlayerDamaged", function(player: Player, data: buffer)
print(player.Name, "sent damage data")
end)net:CreateRemote("Function", "GetInventory", function(player: Player, data: buffer)
return { "Sword", "Shield", "Potion" }
end)net:CreateRemote("Event", "SecureChat", function(player: Player, data: buffer)
print("Encrypted message received from", player.Name)
end, { IsEncrypted = true })Fires a RemoteEvent from the client to the server.
-- send a damage value to the server
net:FireServer("PlayerDamaged", { damage = 25, weapon = "Sword" })Calls a RemoteFunction from the client and waits for the server's return value.
local inventory = net:InvokeServer("GetInventory")
print("My inventory:", inventory)Fires a RemoteEvent to one specific player.
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
net:FireClient("PlayerDamaged", player, { damage = 0, weapon = "None" })
end)Fires a RemoteEvent to every connected player.
net:FireAllClients("PlayerDamaged", { damage = 10, weapon = "Explosion" })Fires a RemoteEvent to all players except the one(s) specified. Accepts a
single Player or a {Player} array.
-- exclude a single player
net:FireAllClientsExcept("PlayerDamaged", excludedPlayer, { damage = 10, weapon = "Explosion" })
-- exclude multiple players
net:FireAllClientsExcept("PlayerDamaged", { playerA, playerB }, { damage = 10, weapon = "Explosion" })Fires a RemoteEvent to an explicit list of players.
local targets = { playerA, playerB, playerC }
net:FireClients("PlayerDamaged", targets, { damage = 50, weapon = "Sniper" })!
InvokeClientandInvokeAllClientscan infinitely yield if a client disconnects mid-invocation. Always wrap call sites in a timeout orpcallin production.
Calls a RemoteFunction on a specific player and waits for their return value.
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
local clientData = net:InvokeClient("GetInventory", player)
print(player.Name .. "'s inventory:", clientData)
end)Invokes all connected players concurrently and returns a {[Player]: any}
table of their responses. Failed or disconnected players will return nil.
local allStuff = net:InvokeAllClients("getStuff")
for player, stuff in allStuff do
if stuff then
print(player.Name, "->", stuff)
else
print(player.Name, "didnt respond")
end
endConnects a callback that fires whenever the server sends to this client.
Returns an RBXScriptConnection so you can disconnect to avoid mem leaks
local connection = net:OnClientEvent("getCountry", function(data)
print("hello", data.name, "from", data.country)
end)
-- disconnect when no longer neede
connection:Disconnect()Sets the callback the server receives a return value from when it calls
InvokeClient. If you for some reason decide to assign it twice, it'll
replace it.
net:OnClientInvoke("X", function()
return { "X", "Y", "Z" }
end)
-- unregister later if needed
net:OnClientInvoke("GetInventory", function() end)Any remote can be created with IsEncrypted = true. The key is generated on
the server and synced to clients automatically via attirbutes.
-- server
net:CreateRemote("Event", "payload_thing", function(player, data)
print("Secure data from", player.Name)
end, { IsEncrypted = true })
-- client - FireServer, InvokeServer, OnClientEvent, OnClientInvoke all
-- handle encryption/decryption
net:FireServer("payload_thing", { secret = "hello" })