RemoteComponent
RemoteComponent is a component extension that allows you to easily give networking capabilities to your components.
You can access the server-side component from the client by using the .Server
index
on the component. You can access the client-side component from the server by using
the .Client
index on the component.
-- MyComponent.server.lua
local MyComponent = Component.new {
Tag = "MyComponent",
Ancestors = {workspace},
Extensions = {RemoteComponent},
}
MyComponent.Client = {
TestProperty = RemoteComponent.createProperty(0),
TestSignal = RemoteComponent.createEvent(),
}
function MyComponent.Client:TestMethod(player: Player)
return ("Hello from the server!")
end
-- MyComponent.client.lua
local MyComponent = Component.new {
Tag = "MyComponent",
Ancestors = {workspace},
Extensions = {RemoteComponent},
}
function MyComponent:Start()
self.Server:TestMethod():andThen(print)
end
Fast tagging and untagging
You can encounter issues if you untag and then retag again quickly or unparent and reparent to the same location on the server. This is because the server will rebuild the component, but the client will not recognize that there was a change as collectionservice wont think anything is different and their remotes can become desynced.
RemoteComponent Usage Limitations
Accessing .Server
or .Client
is only safe to do so once the client has completed its
extension 'Starting' cycle and began its :Start()
method
Yielding accidents
When using RemoteComponent, you must have both a client and server component. If you do not, then the client will yield until the server component is created. If only one side extends RemoteComponent, then you may encounter infinite yields.
Types
RemoteComponent
interface
RemoteComponent {
Client:
table?
--
Only available on the server. Set this to a table to expose it to the client.
Server:
table?
--
Only available on the client. The indices of this are inferred from the server.
}
Functions
createEvent () -> MARKER
RemoteComponent.
createEvent () -> MARKER
(
) →
(
)
Redirects to NetWire.createEvent
createUnreliableEvent () -> MARKER
RemoteComponent.
createUnreliableEvent () -> MARKER
(
) →
(
)
Redirects to NetWire.createUnreliableEvent
createProperty (initialValue: any) -> MARKER
RemoteComponent.
createProperty (initialValue: any) -> MARKER
(
) →
(
)
Redirects to NetWire.createProperty