Hello,
I am currently working on a game where you open ‘packs’ and find cards. Yesterday I posted a thread of how I would need to replicate tables on a server to a client (Replicate Tables from Client to Server) and I did that using remote functions.
However the problem I am encountering is that let’s say you have these tables on the server (a server script) :
local PackedCards = {
} --Here you put Cards that you find when you open a pack.
local NewCards = {
} --Here you store cards that have been found for the first time when a pack is opened.
local DuplicateCards = {
} --Here you store cards that were found as duplicates.
The problem is that since these tables are created on the server, when for example two players are in-game and they open a pack (which should contain 3 cards) , the ‘PackedCards’ table stores & stacks all cards of all players in the server, this caused an issue when for example ‘Player1’ opens a pack he finds 3 but when ‘Player2’ opens a pack he finds 6.
I was thinking it’s because all the addition of items to the table was done on the server whenever the player clicks something on the client, so I am thinking of just creating the tables on the server, replicating them on the client and then do all the modifications on the client. Is this the correct approach?
Note : Sorry if I didn’t use the correct method to format the code blocks.
You’ll need to find a way to create your system so that when clients make requests, the server files it under the player rather than a general table. Right now, your current code is set up so that all player actions use the same table. Therefore, either
You create an indice in each table of the player’s UserId and perform the actions under their name by changing any lookup statements in these tables to Table[Player.UserId].
You create a larger table and use their UserId as an indice. Under each player’s indice, all three of these tables will be there. You then do Table[Player.UserId].DuplicateCards or whatever.
I recommend the second over the first for the sake of consistency and avoiding redundancy, but whatever works for you is good enough. Here are some examples of what your structure may look like.
Hmm, yes this makes sense it doesn’t look that complicated to put in a data store either.
Thank you!
Note : btw, I just noticed you were editing my posts removing the ‘[HELP]’ off my titles, I didn’t know it wasn’t allowed or something but thanks for making me aware, even though I realized after posting three times xD
That was just an example of how your table would look. You don’t need an actual username (and you shouldn’t use it either unless it’s for display purposes). Stick with only trying to get a UserId indice into your table.