So currently I’m making a game where a global datastore is used to store “websites”. My problem that I used to have was that it would duplicate your websites when saved. So to fix this I tried putting a system where it would take the websites that have the same user id as you and take them out of the datastore. Then finally it would just save normally by adding your websites to the rest in the datastore. But the problem is is that instead of only taking out your websites, it just takes out all of the websites from the datastore. Also, yes yes I know this is probably a bad way to do this, so please tell me how I could do it better!
Well you could store the websites in a table and index each website by their userid plus name as a string?
That way you could call a website from the data without taking out all of it?
Are you sure you’re using the correct user ID when you’re access the datastore? You could try printing out the user ID to make sure it’s correct.
Also keep in mind that if you’re running a test server, the user ID is going to be really short, so if you’re getting strange results from the print that’s why. It shouldn’t affect the results.
If the user ID is correct, the problem may be that the server is shutting down when you leave the game. If that’s the case, this article is very helpful. (I did not write it.)
You should post the code for this. Can’t you just set the table[userId] = TheirWebsiteData
? This should just overwrite it, and then you can set it in the datastore (using UpdateAsync hopefully!) If they have multiple websites, you can save a table within a table. table[userId] = {[1] = website1data, [2] = website2data}
I would suggest saving a dictionary of their websites within a single key under their username that holds the websites, and then simply update the datastore when they leave or do something really important.
To be clear, changing the key with table[key] = newvalue
should overwrite/erase the old value, use this instead of table.insert()
if that is what you are trying to achieve.