I need to keep this short and simple as it could be very long and nobody would read it. But try your best to understand. So I currently have this issue with my network where the data for one client replicates across to others. For example, if I hatch a pet (in which goes into a table), and I have my function to update data (in which is a function to update my data table, named serverTable, where accessing the index of their table is by Player.Name), FireClients to them so they can receive an update to their UI.
That was a mouthful, but I am not done. If the other client opens an egg (I have literally printed the Player parameter in my remotes/functions and it doesnt print any other clients). They now have the pet the other client hatched, adding on to what they hatched. This doesn’t go for just eggs, but every data index, so if client 1 spent 30 coins client 2 spends 70. This is seriously confusing, and I cannot find the issue for it. If you still don’t understand, I can provide code snippets to maybe help you understand better. ( And no, I don’t do any FireAllClients on data).
Client data is independent across all clients, the server is responsible for replicating data and changes to client. (As long as filteringEnabled is enabled)
Yeah I wasn’t specific, my bad, but for my remotes like FetchData which returns their table, so serverTable[player.Name], and a function UpdateData, which updates their table by serverTable[Player.Name] = newdata, which works fine but data replicates to both clients.
Yeah, but the server is handling it like both clients have the exact same data (or probably every client I have only tested two). I use a remotefunction to send their datatable to the client, but that shouldn’t replicate for both??
I’ve had a similar issue before and I know what may be happening.
When I was giving the player a new data table, it wouldn’t give them a new table which caused all players to share the same table which causes the same issue here. This code should fix it.
local save = datastore:GetAsync(Key .. player.UserId) or {} -- {} is the default data table that you use
hmmm, well if your indexing a table based off certain players and returning that data then it definitely shouldn’t replicate. Are you able to provide code where the table is being updated?
I think it’d be helpful if you provided server code. It seems like theres an error in the way you’re indexing serverTable, such that all players somehow get matched to the same playerdata element.
This is where I assign them to the table, and load their data. LoadData is just a function in my data module that returns if a getAsync was successful or not.
So this is actually a bit mysterious but important in programming. When you use simple variables like bool, string, number, etc. they all pass by value. So something like val1 = val2, copies the value of val2 and val1 is set to that. But, with tables they’re passed by reference, so val1 = val2 means val1 points to the same table at the address of val2. When copying tables iterate through all pairs, instead of that format and see if that helps.
That worked. Yeah, I don’t know why I didn’t iterate looking back at it. Thank you so much for taking your time to help me though, this issue was driving me up the walls. I learned something from this. Have a good rest of your day! (And thank you to the others who helped as well.)