I’m using Replica by loleris, I don’t understand, is there any way I can get a replica on the client?
I use .OnNew and .RequestData in one script, but I need to use it in other scripts too.
So basically, on the client, you only get the Replica when it’s sent from the server — either through .OnNew or when you call .RequestData(). But once you have it, if you want to use that same Replica in multiple LocalScripts, you gotta store it somewhere global that all your scripts can access.
Best way to do it is to make a ModuleScript (like a little storage box for your Replica).
Here’s how you’d do it: 1. Make a ModuleScript in ReplicatedStorage (name it something like ReplicaStore): – ReplicaStore local ReplicaStore = {} ReplicaStore.PlayerReplica = nil – this will hold your replica return ReplicaStore 2. In the LocalScript where you’re using .OnNew and .RequestData: local ReplicaController = require(game.ReplicatedStorage:WaitForChild(“ReplicaController”)) local ReplicaStore = require(game.ReplicatedStorage:WaitForChild(“ReplicaStore”)) – This gets fired when the server sends the Replica ReplicaController.OnNew:Connect(function(replica) ReplicaStore.PlayerReplica = replica – save it so other scripts can use it end) – Request the data from the server ReplicaController.RequestData() 3. Now in any other LocalScript where you need the Replica: local ReplicaStore = require(game.ReplicatedStorage:WaitForChild(“ReplicaStore”)) – Wait for the replica to exist before using it repeat task.wait() until ReplicaStore.PlayerReplica local replica = ReplicaStore.PlayerReplica print(replica.Data) – or whatever you need to do
This way, you’re only setting it up once, and all your scripts can just grab it from the store when they need it.