Net
Basic networking module for creating and handling static RemoteEvents and RemoteFunctions.
Functions
RemoteEvent
Gets a RemoteEvent with the given name.
On the server, if the RemoteEvent does not exist, then it will be created with the given name.
On the client, if the RemoteEvent does not exist, then it will wait until it exists for at least 10 seconds. If the RemoteEvent does not exist after 10 seconds, an error will be thrown.
local remoteEvent = Net:RemoteEvent("PointsChanged")
UnreliableRemoteEvent
Gets an UnreliableRemoteEvent with the given name.
On the server, if the UnreliableRemoteEvent does not exist, then it will be created with the given name.
On the client, if the UnreliableRemoteEvent does not exist, then it will wait until it exists for at least 10 seconds. If the UnreliableRemoteEvent does not exist after 10 seconds, an error will be thrown.
local unreliableRemoteEvent = Net:UnreliableRemoteEvent("PositionChanged")
Connect
Connects a handler function to the given RemoteEvent.
-- Client
Net:Connect("PointsChanged", function(points)
print("Points", points)
end)
-- Server
Net:Connect("SomeEvent", function(player, ...) end)
ConnectUnreliable
Connects a handler function to the given UnreliableRemoteEvent.
-- Client
Net:ConnectUnreliable("PositionChanged", function(position)
print("Position", position)
end)
-- Server
Net:ConnectUnreliable("SomeEvent", function(player, ...) end)
RemoteFunction
Gets a RemoteFunction with the given name.
On the server, if the RemoteFunction does not exist, then it will be created with the given name.
On the client, if the RemoteFunction does not exist, then it will wait until it exists for at least 10 seconds. If the RemoteFunction does not exist after 10 seconds, an error will be thrown.
local remoteFunction = Net:RemoteFunction("GetPoints")
Handle
This item only works when running on the server. ServerSets the invocation function for the given RemoteFunction.
Net:Handle("GetPoints", function(player)
return 10
end)
Invoke
This item only works when running on the client. ClientNet:
Invoke
(
name:
string
,
...:
any
) →
...any
Invokes the RemoteFunction with the given arguments.
local points = Net:Invoke("GetPoints")
Clean
This item only works when running on the server. ServerNet:
Clean
(
) →
(
)
Destroys all RemoteEvents and RemoteFunctions. This should really only be used in testing environments and not during runtime.