The Best and Easiest Way To Save and Load Data

Hello and welcome, this is a short tutorial on how to set up Profile Service for loading and saving data. This tutorial is not for complete beginners as you must know how to navigate Roblox Studio efficiently. I am by no means associated with the developers who created Profile Service and this is NOT an ad or sponsorship, this is simply a quick tutorial on how to manage data. Also, please note that the way I am setting this up is based off of MonzterDEV’s How to Make a Simulator on Roblox in 2022! tutorial. It’s a great tutorial and he is a very good scripter, please go show some support to him by subscribing to his YouTube channel here as he is the only reason I know how to work with Profile Service. Anyways, let’s get started with the tutorial.

Before we begin scripting we actually have to set up the explorer, that way it’s easier to keep track of the Profile Service module when we call it in other scripts. I suggest making a folder called Libs, Libraries, or Modules. For this tutorial I’ll be calling mine Libs. Make sure to put this folder in ServerScriptService. Once you’ve done that, download the Profile Service module here. Once you’ve got it, it should be in the Recent Models or My Models section of the toolbox. Put the Profile Service module script into the Libs Folder. Once your done, it should look like this:

image

Now, we need to add another Folder to ServerScriptService. Call this one PlayerData. Then add a module script into that folder, we’re gonna name this to Template. This
module script is going to be used as a template for data, thus the name Template.

image

First off, heading into the Template module script, rename the variable from module to Template.

image

Then we need to set the Template to a table, for now we will keep it simple, adding just three stats, Coins, Gems, and Rebirths. The numbers represent the amount of Coins, Gems, or Rebirths the player starts out with when they first join the game, in my case the player starts with just 250 Coins. Also, if you are going to add more data, make sure to put a comma after it.

image

Now we need to add another module script the the PlayerData Folder, call this one Manager. This is the module we will require in our other scripts when we need to access a player’s data.

image

In the Manager module script change the variable from module to Manager. Also we need to create a blank table to hold the players Profile, this will be used to hold all of their data

image

Next up we’re gonna add a script to the PlayerData Folder, make sure this one is just a normal script and not another module script. Name it to Data.

image

Start off by creating some simple variables for the Players and ServerScriptService.

image

Then we’ll need to get the Template, Manager, and ProfileService modules.

image

Next up we will create a store for the profiles.

image

Now, we need to create an argument, this will be the Key. Think of the key as being the holder of all data. You can name the key to whatever you want but keep in mind that if you change it, all the data will be lost. If you accidentally change it don’t worry as you can just change it back and all the data will be recovered. For now we should name the key to Test, but once you launch your game you should change it to something like Production. The second argument will be our Template.

image

Now we will make a function to load a players profile.

image

We’re gonna need to make another key for the profile, we’ll take advantage of the UserId that each way player has their own unique key.

image

Now were are going to make sure that we actually DO have the player’s profile, we’ll do this by kicking the player if we don’t. Start off by creating a kick message variable, make sure it is in all caps as it is a constant variable. This means it will never change. You can set the kick message to whatever you want or you can copy mine. Also, if you are confused as to how it is on line 10, we simply just put it between the ProfileStore variable and the LoadProfile function.

Now that we have a kick message, we can go back into the LoadProfile function and actually use it and kick the player if we do not get their data.

image

If we are able to find the player’s profile then we have to run some methods on it.

image

Then we need to check if the player is a descendant of Players and add the profile to the Manager.

image

Then we need to call the function so that it actually loads the players profile but first we’ll need to loop through all the players so that the script doesn’t load after other players have already joined the game.

image

Then we need to listen for when the player leaves so that there are no data leaks.

image

Almost done, now we will set up the leaderstats. We’ll do this by creating a function near the top of the script (right below the kick message constant).

image

Firstly, create a variable for the profile inside the CreateLeaderstats function.

image

Now lets make the leaderstats folder. Make sure to have the leaderstats name and variable spelled exactly how I have.

image

Now we can add the stats to the leaderstats. Make sure to change Coins, Gems, and Rebirths to whatever stats you have in your Template module script.

image

Then we of course need to call the CreateLeaderstats function. We’ll do this right after we set the players profile in the manager table.

image

And just like that we’re all done. Before you test it out make sure to go up to the game settings in the Home tab

image

and set Enable Studio Access to API Services to true.

Now click play and you should have working leaderstats able to load and save data.

image

Hopefully you guys enjoyed the tutorial! All credit goes to developers of ProfileService and MonzterDEV. Subscribe to MonzterDev on YouTube! For more information on Profile Service go to their website here. Please leave me feedback on how I did with this tutorial, it’s my first time making a tutorial and I would love to know what I did wrong and how I can make my future tutorials better. Part Two is coming soon (Adding and Removing Data!).

That’s all for today, buh bye
-Nameless.

38 Likes

If this is a tutorial, put in in #resources:community-tutorials, #help-and-feedback:scripting-support is only for help with programming.


Can you guys like the post instead of linking my comment, cuz I don’t want it to look like I’ve made the post

9 Likes

I’ll change that right now! Thanks for letting me know!

2 Likes

I would absolutely love to possibly consider switching to ProfileService given how effective and potentially useful it may turn out, but it is unfortunate because I have already based all of my game’s data saving features on the default Roblox DataStoreService, and as far as I am aware, migrating over would wipe everyone’s data :smiling_face_with_tear:

1 Like

Yeah, that’s unfortunate that you can’t transfer the data. At least not that I know of.

1 Like

Yeah I agree. If I could, I would definitely consider it

1 Like

You can! But it would require mapping the data. This would be something you’d have to craft by hand but may be worth the amount of effort you put into it.

Simple example is when the player joins read all of their data, don’t delete the data just yet though from the old DataStoreService and put a Migrated = true in their Profile Store. Then, when everything is seen to work and no one has experienced data loss, delete the old DataStoreService.

Keeping the old one is so if any issues come up you can manually force their data into their Profile Store.

4 Likes

This does seem cool but also very complicated :sweat:

I will take a look into it though, if I can figure it out. With this in mind, I’ll consider making the switch to ProfileService, or DataStoreService2, whichever is better. Then, I can try to create this mapping system

Seriously, thank you though for this reply. It seems very interesting

3 Likes

Amazing tutorial, create part two asap

1 Like

What I would do to transfer to profile service
Get profile of player if data is new then try to get the old from your old datastore and just paste it in your profile

3 Likes

Thanks so much! I’ll be on part two soon!

2 Likes

Thank you for this reply! I believe it will be useful in the future :smile:

Looking forward to part two. Also to anyone new with profile service and data stores to update the leaderstats you must also use Manager[player].Data.Cash to modify it in another script.

1 Like

Wow, I’m super happy to see the knowledge shared around. This was extremely easy to follow along with and I think it turned out great! I hope more people find this method of managing player data.

2 Likes

Hey if you were to do part 2, what would it have? Is there more to add on to this type of system or is there like an update version now

Your template must have this value or another value set to nil (non-existant). Check to see if you specified the variable.