Skip to main content

networkClient

This item only works when running on the client. Client

The client counterpart of network.

Properties

ClientRemoteProperty

Read only
networkClient.ClientRemoteProperty: ClientRemoteProperty

ClientRemoteSignal

Read only
networkClient.ClientRemoteSignal: ClientRemoteSignal

Functions

allFromParent

networkClient.allFromParent(parentInstance) → {[string]{[string]any}}

Returns an array of all networks dispatched to parent.

-- Server
local Workspace = game:GetService("Workspace")

local network1 = network.Server.new("Test1", Workspace)
network1:append("status", "not good mate")
network1:dispatch(Workspace)

local network2 = network.Server.new("Test2", Workspace)
network2:append("status", "good mate!")
network2:dispatch(Workspace)

-- Client
local Workspace = game:GetService("Workspace")

for _, networkObject in Network.client.fromParent(Workspace) do
	print(networkObject.status) 
end

--> "not good mate"
--> "good mate!"

fromParent

networkClient.fromParent(
namestring,
parentInstance,
timeoutnumber?
) → Promise<DispatchedNetwork{[string]any}>

Returns a promise which is resolved once a network with the name of name, is dispatched to parent. If a network with the name of name is already dispatched to parent, the promise will immediately resolve.

For e.g:

-- Server
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Workspace = game:GetService("Workspace")

local network = require(ReplicatedStorage.Packages.network) 

local testNetwork = Network.Server.new("Test")
testNetwork:append("method", function(player)
	return string.format("hi, %s!", player.Name)
end)

-- Dispatch the network to workspace:
testNetwork:dispatch(Workspace) 

-- Client
local Workspace = game:GetService("Workspace")

-- Get the network of name "Test", dispatched to workspace
local testNetwork = network.client.fromParent("Test", Workspace):expect()
print(testNetwork.method()) --> "hi, bubshurb!"

You can also pass in timeout which will result in the promise to be rejected (if it hasn't resolved in time). timeout will default to 20 seconds.

Show raw api
{
    "functions": [
        {
            "name": "allFromParent",
            "desc": "Returns an array of *all* networks dispatched to `parent`.\n\n```lua\n-- Server\nlocal Workspace = game:GetService(\"Workspace\")\n\nlocal network1 = network.Server.new(\"Test1\", Workspace)\nnetwork1:append(\"status\", \"not good mate\")\nnetwork1:dispatch(Workspace)\n\nlocal network2 = network.Server.new(\"Test2\", Workspace)\nnetwork2:append(\"status\", \"good mate!\")\nnetwork2:dispatch(Workspace)\n\n-- Client\nlocal Workspace = game:GetService(\"Workspace\")\n\nfor _, networkObject in Network.client.fromParent(Workspace) do\n\tprint(networkObject.status) \nend\n\n--> \"not good mate\"\n--> \"good mate!\"\n```",
            "params": [
                {
                    "name": "parent",
                    "desc": "",
                    "lua_type": "Instance"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "{ [string]: { [string]: any } }\n"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 128,
                "path": "src/network/client/init.luau"
            }
        },
        {
            "name": "fromParent",
            "desc": "Returns a [promise](https://eryn.io/roblox-lua-promise/) which is resolved once a network with the \nname of `name`, is dispatched to `parent`. If a network with the name of `name` is already dispatched to\n`parent`, the promise will immediately resolve.\n\nFor e.g:\n\n```lua\n-- Server\nlocal ReplicatedStorage = game:GetService(\"ReplicatedStorage\")\nlocal Workspace = game:GetService(\"Workspace\")\n\nlocal network = require(ReplicatedStorage.Packages.network) \n\nlocal testNetwork = Network.Server.new(\"Test\")\ntestNetwork:append(\"method\", function(player)\n\treturn string.format(\"hi, %s!\", player.Name)\nend)\n\n-- Dispatch the network to workspace:\ntestNetwork:dispatch(Workspace) \n\n-- Client\nlocal Workspace = game:GetService(\"Workspace\")\n\n-- Get the network of name \"Test\", dispatched to workspace\nlocal testNetwork = network.client.fromParent(\"Test\", Workspace):expect()\nprint(testNetwork.method()) --> \"hi, bubshurb!\"\n```\n\nYou can also pass in `timeout` which will result in the promise to be rejected (if it hasn't resolved in time).\n`timeout` will default to `20` seconds.",
            "params": [
                {
                    "name": "name",
                    "desc": "",
                    "lua_type": "string"
                },
                {
                    "name": "parent",
                    "desc": "",
                    "lua_type": "Instance"
                },
                {
                    "name": "timeout",
                    "desc": "",
                    "lua_type": "number?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise<DispatchedNetwork: {[string]: any}>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 174,
                "path": "src/network/client/init.luau"
            }
        }
    ],
    "properties": [
        {
            "name": "ClientRemoteProperty",
            "desc": " ",
            "lua_type": "ClientRemoteProperty",
            "tags": [
                "Read only"
            ],
            "source": {
                "line": 13,
                "path": "src/network/client/init.luau"
            }
        },
        {
            "name": "ClientRemoteSignal",
            "desc": " ",
            "lua_type": "ClientRemoteSignal",
            "tags": [
                "Read only"
            ],
            "source": {
                "line": 19,
                "path": "src/network/client/init.luau"
            }
        }
    ],
    "types": [],
    "name": "networkClient",
    "desc": "The client counterpart of [network].",
    "realm": [
        "Client"
    ],
    "source": {
        "line": 7,
        "path": "src/network/client/init.luau"
    }
}