Suphi's DataStore Module

Tried doing this, it worked but the only issue is that, I believe due to .Changed signal being discontinued the StateChanged function no longer works properly, causing the leaderstats to not update.

1 Like

What script do you open the datastore in?

Actually, after looking further the StateChanged function seems to be working perfectly, considering it printed 1337. What’s the actual issue you’re facing?

If it’s the leaderstats, you don’t seem to be changing the leaderstats value, only the datastore’s value.

After adding 100 to dataStore.Value.Cash, do the following:

dataStore.Leaderstats.Cash.Value = dataStore.Value.Cash

to visually update the leaderstats value.

Additionally, if you plan to increment stats multiple times or by different amounts from different scripts, you can also create a custom function in each dataStore as seen here:

This is useful to not repeat the same code multiple times, and it can be changed by just changing the function.

1 Like

Thank you very much for sharing this resource!

I had been receiving reports of data loss in my game for some time and had been searching for a module with a stable session lock feature when I came across this one. It has been running smoothly so far.

I truly appreciate it!

(I’m also using Packet—thank you for that as well!)

2 Likes

How would one go about making a function that can edit nested values without having to configure where it is? So then with one function I could edit things in Statistics or even Settings?
wefewfwf

ewfwefewf

1 Like

Dunno if this is the best option, but you could probably loop through the datastore value and if you reach a table recursively loop through it for the value?

The problem would mainly arise if you come to a point where the template looks like this (in which you’d HAVE to include a context argument):

{
    Money = 0,
    Resources = {
        Carrot = {
            Amount = 0,
            Seeds = 0,
        },

        SomethingElse = {
            Amount = 0,
            Seeds = 0,
        }
    }
}

It would be pretty useful to manage all of this in a singular function.

You could probably shift around the values to “Carrots” and “CarrotSeeds”, but it just looks less organized.

I dont think Suphi is gonna respond but im making my own function so I’ll be back when I come with a solution lol.

1 Like

Ngl I give up it’s too much thought processing for my small mind :rofl:

1 Like

you can pass in a array for the key

function Set(datastore, keys, value)
    if datastore.State ~= true then return end
    local tableValue = datastore.Value
    local lastKey = table.remove(keys)
    for index, key in keys do tableValue = tableValue[key] end
    tableValue[lastkey] = value
end



playerDatastore:Set({"key1", "key2", "key3"}, true)
3 Likes

You should fix the annoying type error you get for passing a number as the second argument by default. Instead, warn/error if a number is passed in as the scope.

This module follows Roblox’s rules:

but it should be very easy for you to modify the module to accept numbers or strings

2 Likes