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:
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.
First off, heading into the Template module script, rename the variable from module to Template.
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.
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.
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
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.
Start off by creating some simple variables for the Players and ServerScriptService.
Then we’ll need to get the Template, Manager, and ProfileService modules.
Next up we will create a store for the profiles.
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.
Now we will make a function to load a players profile.
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.
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.
If we are able to find the player’s profile then we have to run some methods on it.
Then we need to check if the player is a descendant of Players and add the profile to the Manager.
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.
Then we need to listen for when the player leaves so that there are no data leaks.
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).
Firstly, create a variable for the profile inside the CreateLeaderstats function.
Now lets make the leaderstats folder. Make sure to have the leaderstats name and variable spelled exactly how I have.
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.
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.
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
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.
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.