[12/20/2020] - Studio bug fix (Online mode is not vulnerable to this)
Fixed a race condition where a profile could be loaded before the live key access check finishes - this bug was introduced with the no yield on require update two days ago. This can be the cause of errors in studio testing.
Quick question - is it possible to bind functions to some kind of event that occurs when data is changed, such as with DataStore2’s :OnUpdate callback?
Just getting into ProfileService and loving the flexibility and scalability!
local ProfileStores = {
["PlayerData"] = ProfileService.GetProfileStore(
"PlayerData",
{ -- Template
A = 0;
B = 50;
}
);
}
if (RunService:IsStudio()) then
for _,Object in pairs(ProfileStores) do
Object = Object.Mock
end
end
It still saves the data even in Studio. What am I doing wrong? Apart from this the module has been great so far.
You aren’t doing anything in that snippet. In the for loop, you are simply setting the local variable Object to Object.Mock. It doesn’t change the reference in ProfileStores.
if (RunService:IsStudio()) then
for key, profile_store in pairs(ProfileStores) do
ProfileStores[key] = profile_store.Mock
end
end
Is what you wanted to do. profile_store in this snippet is a value which is a reference to a table member. Changing it, however, will not alter the member under key inside ProfileStores.
I’m about to integrate this module into my game, that previously used DataStore2.
However I can’t seem to find a way to get an event when the ProfileStore’s Data changes.
I have leaderstats with coin values, and I want them to update whenever the ProfileStore’s Data changes.
In DataStore2 there was :OnUpdate(), but I can’t seem to find a feature for this in ProfileService? :(
There is a wrapper for this module that has all these features. If you do not want to use the wrapper you will have to make your own Getter and Setter functions and a .OnUpdate event.
That’s pretty… alarming. DS2 does a great job providing that concept and this module (that’s supposedly considered better) doesn’t have that method? Yikes.
How difficult would it be to develop my own method on this module that acts as a Changed event every time data changed? I’m just getting started on learning this module but I don’t want to dive to into it if it’s not worth the hassle.
Refer to the post right above yours for a rough example. All you need to do is make a wrapper with setter functions that do whatever side effects you want. Not at all surprising that it doesn’t provide any for you, as it’s one of the main bullet points.
That means there can be data loss if player data gets changed and leaves under the 90 seconds? Pretty sure it is not like that I have not experienced any yet in my game.
OK so I kind of figured out what was going on… and if this is the case, this service is beyond fantastic. I had some code elsewhere causing problems possibly with the releases as it wasn’t as optimized, I think the service was forcing it’s way in regardless my poorly optimized code. I cleared up my parts to make it more smooth in allowing the profile service priority and it is now back to instant in all my test runs.
That’s true but PS does a fine job in ensuring the player does not leave without having current data. I see a “Changed” function as redundant as it saves with even the risky player disconnects.
Somebody just told me that data only saves every 90 seconds and now I’m being told that data saves when you leave the game…(???) If both are true then why bother creating a changed function in the first place if the data is going to save at the end?
Precisely, a changed function would be too redundant in my eyes. Using Profile:Release() will trigger a save of the current state. Wherever your module is that is handling the ProfileService, you want to release when the player leaves, or else the profile is never released, causing problems when the profile is being loaded back in when the player joins a session. If you are trying to do Profile:Save(), it isnt for saving Profile.Data so keep that in mind.
yes, this is neat and all, but there is datastore2, which is a extremely efficient wrapper in which I use. not trying to say profileservice is bad, but there are better wrappers.
A citation is needed, but I believe bereza himself (the person who originally came up with the system Datastore2 uses to save data) has already endorsed ProfileService over Datastore2, presumably because of its ability to save data much more safely compared to DS2.
If there is a reason why you think DS2 has pros over ProfileService that haven’t already been mentioned (like backups), please post them here. I would also encourage you to fully educate yourself on the innerworkings of ProfileService and exactly why it’s the best open-source data management module on the forum that I’ve seen.
Personally, instead of using one over other. I use both wrappers . I use Profile Service for things like inventory system so can design my own interface. And use datastore2 for stats like cash as it’s easy to setup.