Save your player data with ProfileService! (DataStore Module)

Or use DataStore Editor from sleitnick - where you can edit,download and delete data. It costs robux but it is definitely worth buying.

1 Like

I wanted to add my own functions to each profile object without:

  1. Creating new functions for each profile object.
  2. Editing the main ProfileService module.

So I took the following approach:

local profile = profileStores.playerData:LoadProfileAsync("player_" .. plr.UserId)
	if (profile) then
		local mainTable = getmetatable(profile).__index
		setmetatable(
			profile,
			{
				__index = function(self, index)
					local exists1 = mainTable[index]
					if (exists1) then
						return exists1
					end
					return customPlayerProfile[index]
				end
			}
		)
		...

CustomPlayerProfile (module):

local customPlayerProfile = {}

function customPlayerProfile:TestLol()
	print("SUCCESS!", self.Data)
end

return customPlayerProfile

I want to ask, will this cause any errors or bugs in ProfileService and should I continue using this approach or try something else?

The code works though. I called profile:TestLol(). It worked and printed the data stored in the profile.

So I am working on a game a with a group that uses this module, I’ve only noticed how to use it during the last stages of development meaning it’s not going to be efficient for me to transfer all systems to this API.

I am slightly confused on how can I remove a user’s profile entirely from the API after I get all the values I need from it.

I have done process of transferring any data over to new datastore if the user has any existing data here but I am confused on how then I can delete the entire user profile.

How risky is using :OverwriteAsync()? I specifically need it to edit data if the player does not have any active session (is offline).

If you have to ask, then you probably need to use :LoadProfileAsync() instead.

1 Like

Why do I get this error everytime I leave?

ServerScriptService.ServerModules.DataManager.ProfileService:2411: attempt to call a nil value 

This is where the Profile:Release() function is

local function onPlayerRemoving(player)
	local playerProfile = Profiles[player]
	if playerProfile ~= nil then
		DataManager.ProfileRemoving:Fire(playerProfile, player)
		playerProfile:Release()
		print("[Data Manager]: Profile released")
	else
		warn("[Data Manager]: Profile already released!")
	end
end

I tried removing the ProfileRemoving:Fire() line but it still errors, is this a bug in the module?

I’m having trouble saving data from leaderstats. I don’t know how to transfer the value of the leaderstats (Like gems.Value) to Profile.Data.gems, please help!

I saw that we are NOT allowed to use mixed tables, BUT are we allowed to have different key types in different tables?

For instance:

local template = {
   Coins = 0,
   Wins = 0,
   Tools = {
      "Something",
      "Tool1",
      "another thing"
   },
   Settings = {
      Setting1 = false,
      Setting2 = true,
      Detail = "low"
   }
}

Are we allowed to use the example above?

Yes. Mixed key type limitations apply to individual tables only.

1 Like

So im currently trying to use the DataStore Editor 3.0 plugin made by @sleitnick to change a player’s data and have so far gathered this.


Im not sure if i should include the scope or not and am stuck on what the key is to be.

image

If you choose to respond thank you for helping! :+1:

You are using OrderedDataStore option just turn it off.

1 Like

I noticed when I set a metatable on the profile object, Some functions somehow turn into nil, Is this because of the module, or is it because of Roblox?

1 Like

so then do you just use the player’s userid as the key?

1 Like

Well I don’t really know how you set up your profile’s key. You can check it by doing profile:Identify() and see what the key is.

2 Likes

Hi All,

I have a custom data module that sits on DataStore2. Aside from loading it only interacts with datastore2 in one function:
image

I was hoping to only swap this function out but I’m not sure how to directly set a player’s full profile directly. My handler deals with all data manipulation internally so I’d like to avoid having to swap out all the functions.
For context my primary interest in PS is session locking for trading.

Is this possible?

Thanks!

I really like this Datastore, it’s simply to use and easy to understand. The only question I have is, I see you have an autosave feature and you replied to another user that this doesn’t work with ordereddatastores, do you mean it’s not save to call GetOrderedDataStore() even if its outside the profileservice? If so, can I do things to make it so it is safe, as in reduce the amount of autosaving profileservice does?

Edit: Apologies I realized this has been asked many times before, carry on.

1 Like

Say no more! Although other people made tutorials on how to use it, they never really use ReplicaService to present their data to the client’s screen, fear no more because I just created a new topic on how to use both ProfileService and ReplicaService together! Please check it out!

3 Likes

Is there a way to get all profiles ever made without access to the keys? I want to get the profile of every player that ever joined the server so I can transfer their data. Is there a way to do this? Or no option but to let the data be wiped?

Hey @loleris thanks for sharing this, saving me a lot of time. Your docs are next-level.

Will construct a small shrine of you in my next game. Do you prefer gold or blackiron?

Your friend/fanboi,
John

28 Likes

I don’t understand "
– ProfileTemplate table is what empty profiles will default to.
– Updating the template will not include missing template values
– in existing player profiles!"

I also don’t understand the profiles at all (especially in Developer Products - ProfileService)

1 Like