DataStore2 Error HELP

Hi Guys,

I am having this problem with DataStore2. I want it to save my leader stats but the error comes up at this:

DataStore2 Error1

Error3

Error2

Please Help :frowning:

1 Like

What line is the error on? I can’t really tell from the screenshots.
Edit: From the 1st error, it looks like you’ve give the dataStore2 Api a string instead of the player.

It tells you the error on line 1

From what the documentation looks like, you are supposed to give the DataStore2 function the name of the datastore and the player instance, not a bunch of strings and the player. Maybe manually make different datastores for each value.

Ok.

Could you give me an example of what you mean?

1 Like
local coinsDataStore = DataStore2("Coins", player)
local gemsDatastore = DataStore2("Gems", player)

Ok awesome.

So everything else would be alright I just needed to do it like that?

Yes, everything else should work properly.

NOOO don’t require by Id please, you’ll be getting an older version! Get it from GitHub instead! Also requiring by Id will yield until the module is loaded, which could cause .PlayerAdded to not fire for players that joined before that yield completed, even though that’s solvable, Kampfkarren doesn’t update datastore2’s model anymore

1 Like

There are few problems with this, firstly, as @LucasTutoriaisSaimo mentioned, you should get the GitHub version of DataStore2 as to have the latest version.

Secondly, the first parameter in DataStore2.Combine must be a master key, so I recommend the first parameter be “DATA” since you’re giving it one of the names of the values you want as a MasterKey

DataStore2.Combine("DATA","Coins","Gems", Continue with your other values)

Thirdly, on the line of the error, DataStore2() works by giving it the name of the Value you want to retrieve and the player, it’s erroring because the 2nd parameter is a string, not a player. If you want it to get the points for the player

local PointsDataStore = DataStore2("NoobPoints", player)

Although this wil lrequire you to change the PointsDataStore:OnUpdate to accustom for only changing the NoobPoints

Just will be a bit repetitive on your end since you need to make variables for each of the values in your DataStore, but that’s how this works, if you want it to be a more simple, I recommend just putting all the data in a dictionary and using GetTable and SetTable, I recommend reading DataStore2’s API and some of the guides it has to help you improve on using DataStore2

2 Likes

Hi,

Thanks for your reply. I have came across another issue:

HELP SO CONFUSED

I believe that happens if you don’t update the data via changing it by changing a value. Does it work ingame at least? Or are you doing something that should update it like changing a leaderstats value

I fixed a bit of the issues although, I have came across this:

DATA

Although, when I join the game nothing has saved. Is it because of this?

HELP ME

I believe the first bit should be why, when getting values and setting them, say for example you want to get the gems and set them

gems.Value = gemsDataStore(0)

This will try to get what is in your gems datastore and if it finds now, it’s 0. Also what’s in your update functions?

This is the script for my update functions:

Here

Also wait, are you testing to see if it saved when doing another play test in studio? Did you try it out in game?

No I haven’t could it work in game?

Try it out in game, that’s probably the thing then since you probably didn’t do the thing that allows your data to be saved in studio

I have tested it out in game but it still isn’t saving. I have a BoolValue in ServerStorage called SaveInStudio.

Then something is wrong in the way you’re setting the data, may I see the full code so I can see where the issue could be? Send it as a formatted code block so I can be able to easily send you a fix

image