Save your player data with ProfileService! (DataStore Module)

To create a dead session lock you could load a profile in studio testing with API services enabled and killing the studio process in windows task manager.

1 Like

This is a hack! Also it might not work because I haven’t actually tested it.

A possible way may be to remove the profile from the _loaded_profiles field on the ProfileStore that profile belongs to.

:Release() only actually tries to release if the profile is loaded.

And the way that works is by detecting if the profile is active inside _loaded_profiles.

Therefore, if you remove the profile from _loaded_profiles, it would just not actually release it.

image

ProfileStore._loaded_profiles[profile._profile_key] = nil
--// :Release now just doesn't actually do anything.
2 Likes

I seem to be having an issue, and I’ve looked around and can’t find a solution. It takes around 30-80 seconds to load data between different places. Yes I am releasing the profile before the player gets teleported. I’ve looked on the GitHub as well and none of what I’m doing are in mistakes 1 through 4 for troubleshooting. Not sure if it helps, but this is the output when loading happens after those 30-80 seconds.

Try printing out the table of the profile (in studio) and send what the output is.
Make sure you aren’t trying to put any Instances into the profile.

That’s what’s in the picture above. Everything from “220 65 12” down to “Basic” was in the table at the time and they printed just fine.

You can only save tables that are either an array, or a dictionary with only string keys.

And these can only have, booleans, strings, numbers. (Or sub-tables that follow the same rules)

Hello, everytime I try to add more values to a profiletemplate when there is already a datastore, it returns nil for the new values, and I would have to change the name of the profilestore or add a new one for it to register. Is there anyway of adding new values to the template without adding more stores or resetting current ones?

You should be able to call the :Reconcile() function on a profile to fill new in values from the profile template.

1 Like

Would I use it in a for loop, how would I use the Reconcile function?

You should just be able to do Profile:Reconcile() and it should fill in the missing values.
Example: Profiles[Player]:Reconcile()

2 Likes

So I would run that everytime a player gets their data loaded?

Yeah everytime a profile is loaded, call that function.

1 Like

Thank you for the help! Appreciate it

Question, it is erroring with " attempt to call a nil value" Here’s what I am doing:

profile:Reconcile("NewData", saveStructure)

No need for the variables in the Reconcile function. Just do profile:Reconcile()

1 Like

I was actually using an outdated version of ProfileService which didnt include the Reconcile function but it is now fixed. Thank you for the help!

say a player buys a devproduct that gives them 500 coins and they leave before the autosave cycle (every 30 seconds) takes place. Now regarding this I have two questions:

A) Does ProfileService keep that player’s data in the autosave queue, saves it to the datastore when the next autosave cycle takes place, and then clear it out/release the profile if the player is no longer in the game (or maybe the data is force saved when the profile is released?)

OR

B) will I have to call Profile:Save() to make sure that player’s purchase saves

EDIT: Went through the source code, ProfileService does seem to save the data when Profile:Release() is called

It would make sense to save it manually, since relying on autosave intervals doesn’t guarantee saved data. Are you saying after they fully leave the game? Because at that point the server is closed and profile service can’t save it even if it’s in a queue, if you’re saying right before they leave, then sure if the times match up, but I wouldn’t rely on it.

Could anyone guide me to how I would go about using this to save Skills. I understand that you can use this to save a profile that already has pre-writen data inside. But what if i wanted to add something new to the profile table without hardcoding it to the file before hand?

1 Like

Sure thing!
So in my game, I save skills as a table of strings. It’s as simple as table.insert(profile.Data.Skills, “SkillName”) to unlock a skill. When a player character spawns, it will load the skills table and check through the tools folder in server storage for any tool that matches the name. If it finds it, then it clones it and places it in the player’s backpack. This is a very simple version, if your game has different systems then you may need to adjust this idea for it.

1 Like