Replicate your states with ReplicaService! (Networking system)

Is there anyway to set the value for only a player or a group of players? Or to stop listening for changes?

You serialize it? You must have basic data storing knowledge before getting into this type of stuff.

I have basic data storing knowledge. I’m not just walking around with my head cut off, buddy.

I’m asking a simple question. Is there a way or function in this module, because I have already tried to find it in the API, and have failed.

2 Likes

Well, it would be sort of useless to include if serializers already exist.

how do i change the replica data client side?

local CharacterReplicaClassToken = ReplicaService.NewClassToken("Character")

local player -- A Player instance
local character -- A Model instance
local replica = ReplicaService.NewReplica({
  ClassToken = CharacterReplicaClassToken,
  Tags = {Player = player, Character = character, Appearance = "Ninja"},
  Replication = "All",
})

https://madstudioroblox.github.io/ReplicaService/api/#replicatags

Replication - (Default: {} not replicated to anyone) Pass "All" to replicate to everyone in the game and everyone who will join the game later. Pass {Player = true, Player = true, ...} dictionary or Player instance for selective replication.
https://madstudioroblox.github.io/ReplicaService/api/#replicaservicenewreplica

Methods [ScriptConnection]:

		ScriptConnection:Disconnect() -- Disconnect listener from signal

Treat it like any other lua connection.

local NewKeySignal = Replica:ListenToNewKey(path, listener)
NewKeySignal:Disconnect()

bruh moment

1 Like

yes bruh moment

3000 thousand characters

1 Like

all in good fun :stuck_out_tongue_closed_eyes:

i’ve been trying to implement this along with profileservice for a good week now and i feel like i’m only now getting the hang of it

it doesn’t help that there’s not a lot of case examples from the community using this in specific scenarios like there is with profileservice

@loleris hasn’t replied to this thread for about a year now, either because he’s busy or the replies aren’t worth addressing, so maybe we can try to find answers together :smiley:

2 Likes

Yes, I actually already figured it out. It was a kind of hacky way, though. This is better.

No it isn’t. Bytecode doesn’t get deallocated in this context and thus is retrievable by exploiters and technically anybody on Windows via task manager memory dump.

3 Likes

I didn’t know that. Nice to know.

Is there any built-in function which detects when a replica is added on the server?

Is there a way I can detect when key changes in a dictionary? Similar to how ListenToNewKey works but just whenever a key is changed or created.

How do I replicate and set values in a nested table? I want to replicate and set values for “Lock”.

local test_replica = ReplicaService.NewReplica({
	ClassToken = ReplicaService.NewClassToken("TestReplica"),
	Data = {
		Chair = {
			Basil = 0,
			Farm = 2,
			NestedTable = {
				Lock = 3
			}
		}
	},
	Replication = "All",
})

Hi @loleris! I’ve been trying to add a listener to my replica on the client for changes made on the server, but I figured out that ListenToChange() only works with SetValue() and not with SetValues(). The only way I can listen to those changes now is by using ListenToRaw(), so I suppose this is not how it should work/it may be a bug.

how do I even make a listener for server… on your example it looks like I have to create 2 different Data I don’t understand.

1 Like

This is a god sent module, sad I didn’t swap my games over to this quicker. Very simple module but also allows lots of customizations for very specific usecases

Im not sure, but what I did is require ReplicaServiceListeners instead ReplicaService

Why does it take 1 second to update the value? Is that normal? My game updates the data very frequently, I think it will cause some issues in some scenarios but I didn’t face it yet, I was using only profileservices no replica and there is no delay when updating the data

function DataService:SetData(player,path : string,newDataValue)
	
	local PlayerProfile = self:GetData(player)
	local DataReplica = Replicas[player]
	if PlayerProfile and DataReplica then
	
			--PlayerProfile.Data[dataToSet] = newDataValue
			DataReplica:SetValue(path, newDataValue)
		
	end
end

Yeah apparently requiring it just injects it Lol thank you.

1 Like