“Replica” by loleris
(Successor module to ReplicaService)
(WARNING: Full documentation is not done yet - Replica functionality is similar to ReplicaService, but there were changes to some member and method names. You can also find short API docs inside the Replica scripts!)
Read documentation here: (NOT FINISHED)
Replica wiki (Click me)
Get the module here:
Roblox library (Click me)
(If you make a tutorial for this module, please contact me and I might share the link here!)
Consider donating R$ to the creator of ProfileStore (Click here) if you find this resource helpful!
Replica is a Roblox server to client state replication solution which lets the developer subscribe certain players to certain states.
Individual states in the Replica module are called “replicas”. Replicas can only be created and changed server-side, both server and client can connect clean-up tasks for the moment of replica destruction, state changes can trigger listeners on the client-side.
Changes from ReplicaService
Replica is a successor to ReplicaService - you will find that these modules are very similar, but Replica has much shorter member and method names, yield safety in signal listeners, luau types for autocompletion, Roblox streaming support with Replica:BindToInstance()
and several minor performance improvements.
-
There is no longer a
Replication
argument in the Replica constructor - all new replicas are not replicated by default untilReplica:Replicate()
orReplica:Subscribe(player)
are called or the new replica is parented to an already replicated replica. -
The
Parent
argument in the Replica constructor has been removed - You will have to useReplica:SetParent()
after creating a replica instead. -
For listening to Replica destruction, instead of
Replica:AddCleanupTask()
you will now have to useReplica.Maid:Add()
- these are functionally the same.
Basic example
Server-side
local Replica = require(game.ServerScriptService.ReplicaServer)
local replica = Replica.New({
Token = Replica.Token("GlobalData"),
Data = { -- Passed table reference will be used
Score = 0,
Nested = {
Value = false,
},
},
})
replica:Replicate()
task.spawn(function()
while true do
replica:Set({"Score"}, replica.Data.Score + 100)
task.wait(1)
end
end)
replica:Set({"Nested", "Value"}, true)
Client-side
local Replica = require(game.ReplicatedStorage.ReplicaClient)
Replica.OnNew("GlobalData", function(replica)
print(`Replica received client-side! Data:`, replica.Data)
replica:OnSet({"Score"}, function(new_value, old_value)
print(`Score has changed from {old_value} to {new_value}`)
end)
end)
Replica.RequestData() -- Must be called once anywhere in game code client-side
Other resources:
Check out ProfileStore - DataStore wrapper for handling player data