#Changes to module script happens to all values instead of just one

1 messages · Page 1 of 1 (latest)

wanton haven
#

So I'm using module scripts so I can store players data more easily, I have 2 modules scripts one is a constant, where it will be served as a base for every new player, and the other one is PlayersData, where its a module script where will have the contents of Constant cloned into itself into a key that has the name of the player so you can access each individual by their name and access their data, the problem is everytime a change to a data happens, like clicking the cube so you can get more cubes, which was supposed to only happpen to one player, for some reason its happening to all players, and I don't understand why, since im being specific to only do the changes to key corresponding to the player

#

PlayersData its where changes will happen and saved, where constants is just for me to be able to copy into a new player

#

whenever a player joins, i do PlayersData[player.Name] = table.clone(Constants)
where PlayersData[player.Name] creates a new key into PlayersData with the playes name, and then it copies all the information of Constants into that key, and it works perfectly

#

the problem only happens when a change is made

I try to access something like PlayersData[player.Name].Stats.Cube

and make a change such as PlayersData[player.Name].Stats.Cube += 1

and this is usually triggered by a clickdetector where it fetches the player, and then i just inserted into the key, but for some reason that changes applies to allll players

shell oracleBOT
#

studio** You are now Level 4! **studio

wanton haven
#

and i did try to check if maybe it was just the display displaying the wrong value, but no the values themselves are actually changing across all players

vapid hollow
#

when you use table.clone(Constants), you're getting a shallow copy of the Constants table. so like if your constants table has nested tables like Stats or Upgrades all the players will end up sharing those same nested tables, even though the top level player tables are different.

So i think you need to do a deep clone of your constants table. But im not very good with this kind of thing it's js a guess

#

that might not be the issue at all

wanton haven
#

thank you so much, you are a pure genius 🙏

#

i totally forgot about deep clones

#

idk why they exist on the first place, when clone themselves should do the trick, but its all good, I appreciate it