Save your player data with ProfileService! (DataStore Module)

ProfileService is designed for profiles that are acessed by one server at a time - this will not work.

Yeah, you can use ProfileService for anything other than players as long as the individual profiles are used on one server at a time - otherwise you’ll need to make custom code with update listeners and messagingservice.

2 Likes

How would I get the profile? Could i just use a string, like an ID? because what I understand is that it uses the player object? “Profiles[player]”

Edit:Nevermind, I didn’t realize how it was set up fully.

I’ve been wanting to experiment with ProfileService and took the time to do so today after looking at @EncodedLua’s tutorial.

Is there any reason why I should be getting the following warning:

The code is nearly identical to the script provided in the tutorial (except a few variable name changes.) Did I miss a step in the tutorial? Code can be provided if it helps solve this issue.

More info on UpdateAsync queue warnings can be found in the troubleshooting section and this thread.

From the info and personal experience I’ve gathered, such warnings are not dangerous at all as long as you don’t get like a ridiculous amount of them at a time (like 10 every second). I tried to avoid such warnings while coding ProfileService as much as possible, but there are cases where it’s necessary to put a request on queue immediately.

1 Like

Thank you, I feel like an idiot for missing this portion of the documentation.

I’ve also stumbled upon the script not working in Studio (works just fine in a regular game session), is this just something I’ll have to get used to in regards to testing?

found it in the documentation, go figure

1 Like

Not sure if this was answered but if you update the ProfileTemplate, will old players be able to get that data saved, or are there special steps needed to be taken for that to be possible?

1 Like

You can use the Reconcile() method on a Profile, this will compare the existing profile data structure with the data template being used and will fill in missing values.

API - ProfileService (madstudioroblox.github.io)

2 Likes

Thank you for leading me to the API, should’ve clicked on that to start with.

Since you seem experienced with this, do I need to edit any of the module settings or should I be fine keeping them as default?

By module settings are you referring to the ProfileService module?

I haven’t modified any code / don’t intend to and haven’t ran into any problems.

1 Like

Yes that’s what I meant, sorry.

Thank you, I think I’ll just keep them the same.

Do you recommend updating the player table as they earn currency, pets etc or when they leave update it all in one go?

It’s actually a poor use of ProfileService to save data on profile release - this will leave you prone to data loss much more than having Profile.Data updated all the time.

2 Likes

What would be the best way to do this? Use a coroutine and loop every second to update it? Or have .Changed events?

Event based code is generally more clean.

2 Likes

Hello,
I don’t know if this is because ROBLOX is having an issue with datastores or something, but every time I load up my game I get this error:

In the PlayerAdded function, I have this:
image

I added some prints before, and it doesn’t even get to the “if profile ~= nil then” part. I didn’t touch the scripts in a few days and it was working fine before :confused:

What benefits/security this has over normal data stores using GetAsync and UpdateAsync?

I know session locking, but what else other than that. I want to know it before I revamp my whole saving system.

And does it work with existing data stores? Because data stores in my game have some data of different players (not a lot) on it, any way to transfer that over to profile service? Is it possible to make global leaderboards with this? In DataStore2 as far as I know there is no way to make global leaderboards, and that is one reason of me not using it. Does this have the same issue?

ProfileServices handles a lot of things so that you don’t have to think about them. Assuming you already have proper error handling (which ProfileService does for you), when you use GetAsync and UpdateAsync normally, your data is still sometimes susceptible to being overwritten such as when a player joins and leaves quickly.

Since ProfileService doesn’t use DataStore2’s OrderedBackups method, transferring should be easy. However, you should note that you will have to convert old player data to another format (ProfileService stores some metadata along with your actual data).

As for global leaderboards, I’m not sure what the best method is, but right now I simply use a FastSpawn (or spawn/coroutine) in my :ListenToRelease() connection that saves data to a global leaderboard.

1 Like

How will I transfer the data though? Is there a function for it?

Assuming your data format can be stored in a single table, all you’d have to do is:

local your_data -- [table]
Profile.Data = your_data

ProfileService does not have a “format”, but you simply can’t set Profile.Data itself to anything other than a table. Obviously, you can store (mostly) whatever you like inside a table.

Try surfing the documentation and hopefully you’ll get a better understanding of the ProfileService workflow.

1 Like

Go through the troubleshooting manual. If your code does not have faults noted in troubleshooting, you can DM me your data store script source which you can upload to something like pastebin.