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.
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 availible on the server. Set this to a table to expose it to the client.
Server:
table?
--
Only availible on the client. The indices of this are inferred from the server.
}
-- MyComponentServer.lua
local MyComponent = Component.new {
Tag = "MyComponent",
Ancestors = {workspace},
Extensions = {RemoteComponent},
}
MyComponent.Client = {
TestProperty = NetWire.createProperty(0),
TestSignal = NetWire.createEvent(),
}
function MyComponent.Client:TestMethod(player: Player)
return ("Hello from the server!")
end
-- MyComponentClient.lua
local MyComponent = Component.new {
Tag = "MyComponent",
Ancestors = {workspace},
Extensions = {RemoteComponent},
}
function MyComponent:Start()
self.Server:TestMethod():andThen(print)
end