2.1.8 • Published 3 years ago
@rbxts/net-ts v2.1.8
NetTS
You can use with both RobloxTS and Plain LuaU
installation and importing
RobloxTS
npm install @rbxts/net-tsImport
import Net from '@rbxts/net-ts'
const net = new Net()Roblox LuaU
local Net = require(game.ReplicatedStorage.Net).default
local net = Net.new()Events Usage
Server -> Client
To send data on Server to specific player, you have to specify _player property.
Client
net.addListener('random-event-name', ({ property1, property2 }) => {
print(`First param: ${property1}, Second param: ${property2} `)
}, true)Server
net.emit('random-event-name', { property1: 'example', property2: game.GetService("Workspace"), _player: game.GetService("Players").FindFirstChild("Monotter") as Player }, true)Server -> Clients
if you do not specify _player it will automatically call FireAllClients.
Client
net.addListener('broadcast', ({ property1, property2 }: { property1: string, property2: Instance }) => {
print(property2, property1)
}, true)Server
net.emit('broadcast', { property1: 'example', property2: game.GetService("Workspace") }, true)Client -> Server
if you do not specify _player it will automatically call FireAllClients.
Client
net.addListener('kick-itself', ({ reason, _player }: { reason: string, _player: Player }) => {
_player.Kick(reason)
}, true)Server
net.emit('kick-itself', { reason: 'uwu' })Server -> Server, Client -> Client
Server / Client
net.addListener('randomEvent', ({ a, c }: { a: string, c: string[] }) => {
print(`b: ${a}, [d,e,f]: ${c} `)
})Server / Client
net.emit('randomEvent', { a: 'b', c: ['d', 'e', 'f'] })Function Usage
Function Usageonly returns value of first returned listener.Client <-> Client, Server <-> Server
// Sender const result = net.emit('add', { num1: 20, num2: 11 }, false, true) // -> To making it function, simply add true at last parameter print(result) // -> Result will be printed. ;)// Receiver net.addListener('add', ({ num1, num2 }: { num1: number, num2: number }) => { return num1 + num2 // -> now we can use return })Server -> Client
Server -> Client
// Receiver
net.addListener('multiply', ({ num1, num2 }: { num1: number, num2: number }) => {
return num1 * num2
}, true)// Sender
const result = net.emit('multiply', { num1: 2, num2: 5, _player: game.Players.Monotter }, true, true)
print(result)Important Notice
I did not test examples that specified on here so there is a might be a issue on that