How to use DataStore2 - Data Store caching and data loss prevention

Ok, I think I’m understanding this wrong. Could you give me an explanation on how you would store and load a table, because I have no idea what I’m doing with this anymore.

Tables are not handled any differently in DataStore2 from other data types. The error you’re getting is an issue with your code. You are treating invholder as a table, and Lua is telling you it is a string value.

I ended up fixing the error, but it had no effect.

I am not sure how to help any further other than saying that “how do you save tables” is the exact same question as “how do you save”. Tables are not different.

1 Like

How would I use :Get with a table though, if you set the table equal to a value, it just makes it a string. Like where I have

	money.Value = moneystore:Get(500)
	er.Value = erstore:Get(0)
	level.Value = levelstore:Get(1)
	exp.Value = expstore:Get(0)
	maxexp.Value = maxexpstore:Get(500)

How would I do that with a table?

2 Likes

The same way you use :Get on anything else, tables are not treated differently.

Whatever this means, it’s not true. Tables are not treated differently.

The same way you would do it with any other value. Tables are not treated differently. I really am not sure how to help you.

cant we just add playerRemoving

What do you mean by this? DataStore2 already saves when the player leaves.

Is there any plugin like Crazyman32’s Datastore Editor for DataStore2?

Is anything out yet? Can I use Crazyman32’s Datastore Editor?

Is it fine to have so much “datastores” in combined datastore? Is there a (suggested) limit or is it fine to have as many as you want?
I have literally everything there that should be saved…

See: Does CrazyMan's DataStore Editor work for DataStore2? - #6 by MFCmaster1234

2 Likes

The only limit is the 260k character limit, but that’s really hard to hit unless you’re doing something crazy like letting people make buildings or something.

1 Like

i cant configure anything in the server in game putting an item and it never saves
by using this module

Hello! I am using the latest version of DataStore2 and I have recently noticed that some people are losing stats when they leave and join back? I am not sure if this is occurring when the player leaves or when they join. I just find it odd that only some people are having this issue? It has just happened to me there now. I left the game and when I joined back I was reset back to the data I had previously?

This use to happen to everyone when I shutdown all servers but I believe I fixed this issue by getting the lastest DataStore2 module. I tested it with 12 players which is a full server. I shutdown the server and their data stayed. But now I am back to square one and I am losing data again?

Just an update. I had another Datastore repeatedly saving every 60 seconds so that I could do live Leaderboard updates. After about 30 minutes of the server running this datastore starts to fill requests which slowed down the saving process for when a player leaves by 10 seconds.

I think this might have been why data was being lost. I’ve disabled the leaderboards and working on a more efficient way to display them!

1 Like

These are issues with your code, not mine. I apologize, but there’s really not much I can help you out with here.

1 Like

this actually has been happening to a lot of people who use DS2 (the older versions work just fine with the same code) I didn’t know what the issue was, but on another note, you need to add a table of ‘saved’ players… So basically after autosaving a player then the players ‘saved’ value is set to ‘true’ then it’ll wait 6 seconds using spawn() (or coroutine) and set it back to false automatically, allowing you save them again.

local saveInterval = 1
--pseudo code
if(saved[player.Name] == false) then
    local success = save(player)
    if(success==true) then
        saved[player.Name] = true
        spawn(function()
            wait(6)
            saved[player.Name] = false
        end)
    end
else
    print("Player was already saved recently")
end

this will allow you to run through and save all the ‘unsaved’ players way faster without filling up your queue. (don’t copy and paste this, its just pseudo code)

3 Likes

260k character limit per player or per game?
Also, per datastore or per all datastores in game

1 Like

I believe its around 260k characters per key.