Package Exports
- @rbxts/replicaservice
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@rbxts/replicaservice) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
replicaservice-typings
roblox-ts typings for MadStudioRoblox's ReplicaService
Usage
//Client side, errors if used on server!
import { ReplicaController } from "@rbxts/replicaservice"
//Server side, errors if used on client!
import { ReplicaService } from "@rbxts/replicaservice"
//Somewhere in the project, preferrably a .d.ts file:
declare global {
interface Replicas {
ReplicaName: {
Data: {};
Tags: {};
}
}
}
//Modify the Replicas interface to have each Replica class name you use as a key,
//and an object of Data: {} and Tags: {} properties. These should then contain the intended data and tags
//respectively for the replicaReplicaService Basic Usage translated to TS
A .d.ts file
declare global {
interface Replicas {
TestReplica: {
Data: { Value: number };
Tags: {};
};
}
}Server
import { ReplicaService } from "@rbxts/replicaservice";
const test_replica = ReplicaService.NewReplica({
ClassToken: ReplicaService.NewClassToken("TestReplica"),
Data: { Value: 0 },
Replication: "All",
})
while (wait(1)) {
test_replica.SetValue(["Value"], test_replica.Data.Value + 1);
}Client
import { ReplicaController } from "@rbxts/replicaservice";
ReplicaController.ReplicaOfClassCreated("TestReplica", (replica) => {
print("TestReplica received! Value:", replica.Data.Value);
replica.ListenToChange(["Value"], (new_value) => {
print("Value changed:", new_value);
});
});
ReplicaController.RequestData(); // This function should only be called once
// in the entire codebase! Read the documentation for more info.