Suphi's DataStore Module

NVM i didnot even enable API access sorry for bothering :sweat_smile:

2 Likes

What’s the difference? Is one more efficient than the other? I have never had to use session locking but I’m curious in case I’ll have to in the future.

2 Likes

Session locking prevents opening the same datastore key at the same time

So let’s say a player leaves one server to enter another server before the previous server managed to save there data the second server would try to load there data before the previous server saved there latest data this would cause the player to lose data

But if you have session locking the second server would not be able to open the players data until the previous server saved and closed the session preventing them from losing data

By using the memorystore we can ensure that the session lock times out for all servers at the exact same time but if you use os.time() to workout if a session has timed out you can not be 100% sure that all servers will timeout at the exact same time because os.time() uses the operating systems clock and the operating systems clock might not be perfectly in sync between servers this allows SDM to have a smaller timeout for session locks

10 Likes

You can make a custom function inside the datastore

local function Set(dataStore, key, value)
    if dataStore.State ~= true then return false end 
    dataStore.Value[key] = value
    print("DataStore value changed to", value)
    return true
end

game.Players.PlayerAdded:Connect(function(player)
    local dataStore = DataStoreModule.new("Player", player.UserId)
    dataStore.Set = Set
end)

then you can use the function like this

local dataStore = DataStoreModule.find("Player", player.UserId)
if dataStore == nil then return end
dataStore:Set("Key", 69)

you can even use signals

local Signal = require(game.ServerStorage.DataStore.Signal)

local function Set(dataStore, key, value)
    if dataStore.State ~= true then return false end 
    dataStore.Value[key] = value
    dataStore.ValueChanged:Fire(key, value)
    return true
end

game.Players.PlayerAdded:Connect(function(player)
    local dataStore = DataStoreModule.new("Player", player.UserId)
    dataStore.ValueChanged = Signal.new()
    dataStore.Set = Set
end)

then you can connect to the signal like this

dataStore.ValueChanged:Connect(function(key, value)
    print("Changed", key, value)
end)
6 Likes

very cool, but if you ask me profileservice works just fine ._.

1 Like

Does this module prevent item duplication exploit? Just like ProfileService.

What do you mean about that? Like duplicating values or player’s points?

there are many ways a item can get duplicated

are you talking about the one where a player quickly joins a different server before there datastore was saves?

if so then yes this has session locking just like ProfileService that will prevent the next server from loading the data before the previous server has saved it

also when trading items between players you might also want to use the Save function to ensure that both players datastore save after the trade. Take a look at the developer products example to see how to use the Save function

4 Likes

Never mind this feature is related to session locking

Great module. Highly suggest others to use it

-It’s simple
-It’s easy to use
-It’s secure [havent encountered any single error/datastore since I’ve been using it].
-It’s always great to see new ways/datastore modules and learn about them

great job as always
@5uphi

10 Likes

With the documentation and older versions:

3 Likes

rn working on a PR for this, will edit it if possible

2 Likes

How exactly does :Read() work for reading the value of the data store? Every time I use it, I will only give the current state of the datastore, like Open, Closed, or Success.

1 Like

Read will load the current saved value in the datastore not the most recent cached data

If you want the most recent value use open not read

99% of users should not be using read

2 Likes

The way I see it is that this is just a better “version” of profileservice.

4 Likes

it probably is but is it worth learning a new datastore system is what i’m questioning :stuck_out_tongue:

2 Likes

Is there a way to easily access specific data store values in a local script? Or do we have to get it through Server only?

1 Like

The server needs to share it with things like
Remote events, attributes, numbervalues, etc…

1 Like

what pros and cons using this over profile service?

I would say there are the same but , for me ProfileService server communication is better with GlobalUpdate using datastore than suphi datastore than suphi using MemoryStoreService (I need a lot of size for my game)

2 Likes