How can I save data under a string with datastore2?

What I’m trying to save under datastore2 is NOT a player stat. Is it possible to save it under a string like datastore1?

Yes it is possible.

You should look at the error more carefully, it’s telling you that you aren’t calling the function correctly. Looking at the details of your exceptions and applying fixes based on what they tell you is very important.

Before posting threads to this category, you should always attempt to fix your own issues as they are often easier to fix than you perceive them. The second step is to reference documentation if you want to check if what you’re doing is correct.

Look at the error and then look at your code. DataStore2() is receiving two strings which is causing an error because it expects a string (the DataStore2’s name) and a player instance to be passed. Simple fix is to pass the player instead of whatever Id is.

1 Like

Datastore2 is meant for player data. Why would you use it for this? You use your own caching system with DatastoreService.

@colbert2677 I’m not sure if this is because of the original post’s edit, but he did say this isn’t for a player’s stat, so that isn’t particularly helpful. It looks like he’s trying to keep track of the number of users who got the answer correct.

2 Likes

The error stated that it expected {string, player}. So it’s looking for a player to store data, but I gave it a string instead. The issue is I have to use a string, because I’m not storing a player stat

You can’t make APIs do what you want through sheer willpower.

The Datastore2 module is for saving player data. That’s what it does. If you don’t want to do that you need to use something else.

5 Likes

I don’t want to use Datastore1, because there is dataloss

I don’t think you understand what the difference between DataStore2 and DataStoreService is. DataStore2 is just a wrapper for DataStoreService, specifically player data, that uses a specific method of saving (“berezaa”'s method) and good practices (caching, etc) to minimize data loss in most situations. You can still prevent data loss just as effectively with DataStoreService, since that’s what the DataStore2 module uses internally.

5 Likes