Replicate your states with ReplicaService! (Networking system)

I’m curious about this, can’t you just

local function onValueChanged(new_value)
   task.spawn(function()
      --- do things here 
   )
end

?

I’m asking because this is what I’ve always done since using this module, I’d like some insight into your own workflow for this kind of thing if that’s okay

What @Riesegarder said. Also make sure to cleanup the previous connection when connecting the same one again. Otherwise you’ll end up with an extra connection every respawn.

Easiest solution would be to disable ‘ResetOnSpawn’ on the screengui. If that’s possible for your usecase.

The fact that you say this just proves how inconvenient this is in its current form. It’s such a simple fix too, with such a dangerous result if not.

What I did was just go into the module, CTRL + F, and change every (not commented) listener( to task.spawn(listener,. If you put spaces in between your commas be sure to add a space at the end of task.spawn(listener,.

1 Like

Hey, is there a canonical, StreamingEnabled-compatible way to associate an instance with a replica? I’ve been assigning a unique ID to relevant instances through Roblox’s attribute system as a workaround, but it feels a little hacky.

Edit: Just realized replicas already have their own unique IDs I could have been using.
image

Just coming back to this. I realized yeah, why isn’t it the default behavior? I’ve started doing what you’re doing and it does simplify a lot of the things I end up doing.

Just coming back to this. I realized yeah, why isn’t it the default behavior? I’ve started doing what you’re doing and it does simplify a lot of the things I end up doing.

^ idk why this wasn’t posted as a reply to this message

Getting this bug when trying to use Replica:FireAllClients()
image

The relevant code:
image

No idea why it thinks the replica is suddenly nil. I tried printing the ReplicaId before and after the call:
image

image

This is the output:
image

The before the call it prints ReplicaId 3, while within the :FireAllClients() somehow it says nil. What gives?

Dont call it like this: self.Replica.function()
Call it like this, because it’s a class self.Replica:function()

I’m just gonna respond to that with a meme from above.
image

thanks man

1 Like

In a 30 server size game, is getting all player replicas on the client okay? Until recently I only handled the local players profile replica, but I need to grab some data from other players’ replicas. Would this dramatically increase network usage, or would this be alright?

Unreliable events just released. Is replica service still performant?

1 Like

I’m off course not the creator of this module, but I think ReplicaService is supposed to be reliable. So using unreliable events wouldn’t make much sense.

For example: the use case of replicating profile service data. You want to make sure the client receives their latest data. This isn’t what unreliable events are for.

Possibly a setting to toggle it though?

2 Likes

Are you planning on adding more methods to the ReplicaController and ReplicaService to incorporate the new UnreliableRemoteEvents? Methods like FireClientUnreliable, FireAllClientsUnreliable, etc… would be very useful to have.

how do i use client write to server

Client:

repeat wait(0.5) until game:GetService("Players").LocalPlayer.Character

local char = game:GetService("Players").LocalPlayer.Character
local root = char:WaitForChild("HumanoidRootPart")
local prevPos = root.CFrame.p

local replicmod = require(game:GetService("ReplicatedStorage").ReplicaController)

local tweenService = game:GetService("TweenService")

replicmod.ReplicaOfClassCreated("movement", function(reps)
	reps:SetValue()
end)

game:GetService("RunService").Stepped:Connect(function()
	local currPos = root.CFrame.p
	if currPos ~= prevPos then
		game.ReplicatedStorage.RemoteEvent:FireServer(root.CFrame)
		end
end)

game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function(plr, cframe)
	
	local humanroot = plr.Character:FindFirstChild("HumanoidRootPart", true)
	tweenService:Create(humanroot, TweenInfo.new(0.1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false, 0), {CFrame = cframe + Vector3.new(0,0,0)}):Play()
end)

Server:

local repservice = require(script.Parent.ReplicaService)

local receive = repservice.NewReplica({
	ClassToken = repservice.NewClassToken("movement"),
	Data = {CFrame = 0},
	Replication = "All",
})
1 Like

also i want to write client replicate server basics

How do i use FireServer

-- ( `LocalScript` ReplicaTest.client.lua)
local ReplicaController = require(game.ReplicatedStorage.ReplicaController)

ReplicaController.ReplicaOfClassCreated("onserver", function(replica)
	print("TestReplica received! Value:", replica.Data.Value)

	replica:FireServer()
end)

ReplicaController.RequestData() -- This function should only be called once
--   in the entire codebase! Read the documentation for more info.

This module was made for ProfileService in mind. The client should not be able to control the server. Use RemoteEvents for this!

Question loleris, how would I go about wrapping profile.Data in serverscriptservice with a replica so that I can call/view it’s data at any time on the client-side?


This is a huge problem lol

Wrap it in a “Data Service” or DataService Class that sets data to the ProfileStore & sets the data to a replica. You’ll require that class in every script where you feel it’s needed.

2 Likes