UPDATED MODULE CALLED “Replica” HAS BEEN RELEASED - Click for more info
Donate R$ to creators (Click here) If you find this resource helpful!
Madwork - ReplicaService
ReplicaService is a selective state replication system. ReplicaService helps you make server code which changes and replicates any state to select clients.
It’s documented:
ReplicaService wiki
It’s open source:
Roblox library
It’s a perfect fit for ProfileService:
ReplicaService + ProfileService example included in the package
Assume that a state (Wikipedia) is any kind of data that has a present version and may also change at any time in the future, as many times as necessary. The data about a player which you load up during gameplay or save to the DataStore is a state. The color of a part, text shown on a users screen and furniture placed in a player owned house are all states - ReplicaService helps you make server-side code to control and replicate any state to all clients at once or only a select few.
A state (in layman’s terms, a lua table that may contain almost anything) is wrapped with a Replica
- like the name implies, it creates a replica (identical copy) of the wrapped state on the client-side of users you want to see that state. You may define clients who will see that replica, call mutator functions on the Replica
to change the state (will change contents of the wrapped table) and make the clients listen to those changes or simply read the state whenever necessary. Furthermore, a Replica
can be parented to another Replica
(with a few exceptions discussed later), unloaded for select clients and, of course, destroyed.
What’s good about ReplicaService:
-
Just replication, whatever you need replicated - The goal of ReplicaService is to streamline custom Roblox object replication from server to client. ReplicaService avoids being redundant and tackles as few concerns as possible.
-
Chunks & player houses - Selective replication allows you to make a “custom StreamingEnabled implementation” with full server-side control - load in nearby chunks, load in interiors and furniture only when the player enters those areas!
-
“It don’t go brrrrr” - ReplicaService is completely event-based and only tells the client the data that changes - it keeps the network usage low and conserves computer resources.
-
Go big, go small - Use custom mutators for minimal bandwith and gain access to client-side listeners that react to bulk changes instead of individual values. Use built-in mutators for rapid implementations while still keeping your network use very low.
ReplicaService is part of the Madwork framework
Developed by loleris
Minimal implementation example:
-- ( `Script` ReplicaTest.server.lua)
local ReplicaService = require(game.ServerScriptService.ReplicaService)
local test_replica = ReplicaService.NewReplica({
ClassToken = ReplicaService.NewClassToken("TestReplica"),
Data = {Value = 0},
Replication = "All",
})
while wait(1) do
test_replica:SetValue({"Value"}, test_replica.Data.Value + 1)
end
-- ( `LocalScript` ReplicaTest.client.lua)
local ReplicaController = require(game.ReplicatedStorage.ReplicaController)
ReplicaController.ReplicaOfClassCreated("TestReplica", function(replica)
print("TestReplica received! Value:", replica.Data.Value)
replica:ListenToChange({"Value"}, function(new_value)
print("Value changed:", new_value)
end)
end)
ReplicaController.RequestData() -- This function should only be called once
-- in the entire codebase! Read the documentation for more info.