Client data is the same for every client?

Hello Devfourm,

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).

what code did you use? there must be something you’re doing wrong

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
1 Like

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?

1 Like

That didn’t seem to work. I just did:
local defaultData = {
[1] = {} – petInventory

}
local Key = “Key”…player.UserId
local Data = datastore:GetAsync(Key) or defaultData

That’s your issue right there. You’re giving all the players the same table. Try doing:
local Data = datastore:GetAsync(Key) or {[1] = {}}

1 Like

Tried that aswell, along with 17 indexes of data. Should I just show you my data loader whenever the player is added?

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.

1 Like

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. Post3

ohhh I see
newData = defaultData

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.

1 Like

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.)

1 Like

sure thing, glad I could help!
Keep on scripting, ur styles real good and I’m sure u can make some pretty cool stuff.

1 Like