Hi Guys,
I am having this problem with DataStore2. I want it to save my leader stats but the error comes up at this:
Please 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:
Please Help
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?
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
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
Hi,
Thanks for your reply. I have came across another issue:
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:
Although, when I join the game nothing has saved. Is it because of this?
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:
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