[ReplicaService] replica:ArrayInsert() inserts into the profile

Im currently working on a game and I decided to use ProfileService and ReplicaService. Up until now I haven’t had any major issues with these libraries.

After making this FolderInsert function (it inserts a value into a table in the profile while also updating the replica):

function Manager:FolderInsert(player, folder, key) -- performs table.insert(folder, key)
	local profile = self:GetProfile(player)
	local replica = Replicas[player]	
	
	if profile and replica then	
		table.insert(profile.Data[folder], key)
		replica:ArrayInsert({folder}, key)
	end
end

I noticed that ArrayInsert() inserts the key not only into the replica’s Data but also into the table in the profile resulting in the table having two identical elements in it (which I don’t want).

Anyone else ever had this issue? Any help appreciated.

It seems like you’re experiencing an unexpected behavior with the ArrayInsert() function of ReplicaService. This function is designed to insert a value into an array in the replica’s data. However, it should not modify the original profile’s data.

The issue you’re facing might be due to the way these services are designed to work together. ProfileService is meant for server-side data management, while ReplicaService is used for replicating server-side states to the client.

Here’s a suggestion: You could try separating the operations. Perform the table.insert() operation on the profile’s data first, save it, and then perform the ArrayInsert() operation on the replica’s data. This way, you’re ensuring that the operations on the profile’s data and the replica’s data are distinct.

Sorry if I am asking for too much at this point, but how would I go about separating these two operations? I can’t really see an optimal way to do it. Do I separate that into a different function or something like that?

Its alright, No worries. Anyways, You can separate the operations by saving the profile data right after you modify it, and then updating the replica.

If you could, please elaborate on the “save the profile’s data first” part, because as far as I know, you cannot just save the data in a profile.

Also on a side note, your replies are kinda… AI-ish as to say, so if you’re using AI then please stop as you’re only wasting my time.

1 Like

I know my replies look like AI generated, But they aren’t, I am actually trying to keep the Grammar well and Understandable. Also, when I mentioned “saving the profile’s data”, I was actually referring to the concept of ensuring that your changes to the profile’s data are completed before you update the replica. This is to prevent any inconsistencies between the profile and the replica.

Not only were your previous replies almost identical to what I received from ChatGPT after I asked it the same question, but many online AI text detectors also detected your replies as AI with high certainty. The reply you wrote just now might’ve been written by you, but that doesen’t improve your credibility at all.

Anyways, what you’re suggesting is a really bad solution to the problem mainly because it won’t solve anything but also because it would be really bad to yield anything in data related functions using ReplicaService and the operations done on profiles and replicas are separate by design.

Turns out it was my fault and that I wrongly interpreted the functionality of ReplicaService. For anyone wondering just read the docs on the Data parameter of the Replica instance and you’ll know what is wrong here.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.