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.
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.
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!)
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?
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.
Ngl I give up itâs too much thought processing for my small mind
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)
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.