Hello there, me and a team of developers have recently launched CodeClicker, however, the Datastore2 is having issues, such as slower loading. Players are complaining so much, that I have no choice than to come here to find a solution.
Current things that are in the saving list are:
Coins, EXP, Level, CPU Upgrades, SSD Upgrades, Rebirths, Levels, Maximum items, Pets table and equipped pets table.
Here is a part of the codes that includes saving:
local function saveeqdata(petsTBL,player)
--get data
local petData = datastore2(keyequipped, player)
--update datastore
petData:Set(petsTBL, defaultEquippedPets)
petData:Save(petsTBL, defaultEquippedPets)
end
game.Replicatedstorage.UnequipAll.OnServerInvoke = function(plr, mode)
local petData = datastore2(keyequipped, plr)
local DATAFOLDER =
game.ServerStorage.DataFolder:WaitForChild(plr.UserId).Pets
local EQUIPDATA = DATAFOLDER.Parent.EquippedPets
local Table = {}
table.insert (Table, 1,"")
saveeqdata (Table,plr)
updateequippedpet (Table,plr)
end
You have not implemented DataStore2 correctly, you are failing to implement the “Datastore2.Combine” feature.
It looks like currently you handle all 10 datastore tables (Coins, EXP, Level etc) separately. This is throttling your game and will lead to data saving and loading issues.
Read into the (somewhat poorly) explained API made by @Kampfkarrenhere. I’m not going to lie, it could be explained in more depth, but with a little bit of trial and error you should be able to figure out the combine feature.
In short you will want to use the combine feature like so:
Datastore2.Combine(SOMEMASTERKEY, coins, exp, level, cpu, ssd, rebirths…) then ALL OF YOUR DATA WILL BE SAVED INTO ONE TABLE.
To get data you can then call local someData = Datastore2(SOMEMASTERKEY, player):Get(getData())
Then you can access data by indexing it such as:
local coins = someData[“coins”]
This will give you the player’s coins.
It’s quite a tricky concept to explain in a brief forum post, but that’s where you’re going wrong.
Oh? I am fairly new to Datastore2 but have been using that method and have had no problems.
local playerData = ds2(mainKey, player):Get()
local info = DataTable[item]
if info[1] then
playerData["Bools"][item] = true
playerData["Ints"][info[3]] = playerData["Ints"][info[3]]-info[2] -- Minus their currency last.
else
playerData["Ints"]["Points"] = playerData["Ints"]["Points"] - info[2]
if item == "PToH1" then
playerData["Ints"]["Heads"] = playerData["Ints"]["Heads"] +1
This sort of code works fine for me, concluding all changes with “ds2(mainKey, player):Set(playerData)”.
Ah, right. Yeah I have been using just the single branch approach for most of my code, it was just at that particular point I wanted to change both “Ints” and “Bools” in one function, and so just found it easier to call all the data and change only those two branches, then setting the whole thing at the end instead of calling the two branches separately.
Although my approach is different, is it actually dangerous to do? If there’s no risk then I’ll probably keep doing it, and I don’t see why there would be any problems with my method. I appreciate that it is a bit weird, I don’t code much .
Please read incapaxx’s posts. This isn’t how you’re supposed to use Datastore2.Combine. This shouldn’t be the marked solution because it’s not guaranteed to work.