Save your player data with ProfileService! (DataStore Module)

If you’re comfortable with making Lua-style classes, you could create a pretty simple solution easily. In the constructor, give it the Profile and create the signals you need (eg: CashChanged, etc.). Then, just add setter methods that set the value and fire the appropriate signal.

Hey,

I noticed that the data takes over 25 seconds (roughly 30) to load. I don’t have a wait on the releases, but I do realize that the following is printed:

[ProfileService]: DataStore API error (Store:“PlayerData”;Key:“Player_81553363”) - “ServerScriptService.dataRetriever.ProfileService:548: attempt to index nil with ‘UpdateAsync’”

I also realize it gets stuck when I run LoadProfileAsync
Recommendations?

Thanks

Could you show your code that calls LoadProfileAsync?

Sure:

local profile = GameProfileStore:LoadProfileAsync(playerID, “ForceLoad”)

^ where player is “Player_”…player.UserId

This is the really basic implementation of it using ForceLoad, I tried with Steal but it is the same. Noticed sometimes it is fast as lightning then occasionally it is taking a moment. I thought it had something to do with the release but then I ruled that out because leaving causes the release, without any wait.

30 second load is usually the cause of not releasing. You have to be 120% sure your code gets to the point where it releases the profile, every time. Do prints and do some offline server testing.

2 Likes

[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.

Update your module here:
Roblox library
GitHub

2 Likes

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!

ProfileService .Mock is not working.

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.

Object is a reference, not a duplicate.

if (RunService:IsStudio()) then
	for _,Object in pairs(ProfileStores) do
		print(Object == ProfileStores.PlayerData) -- true
		Object = Object.Mock
	end
end

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.

3 Likes

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.

https://devforum.roblox.com/t/profile-interface-effortless-way-of-handling-data-with-profileservice/890904

1 Like

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.

1 Like

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.

No,

When you leave it saves by default .

1 Like

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.

Thanks for the help :slight_smile:

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.

Wait I’m confused.

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?