Save your player data with ProfileService! (DataStore Module)

It’d be helpful if you could show us how you load your players profiles and what you do with them.

not sure what your issue is, but why are you using _G, is this not in a module script, as _G was commonly used for info between scripts, but with modules, any script can require and get the profile info if you make a simple function that is returned that can give the requested profile.

I’m mostly using the default ProfileService template:

PlayerAdded
local function PlayerAdded(player,folder)
	local profile = ProfileStore:LoadProfileAsync("Player_" .. player.UserId,"ForceLoad")
	if profile ~= nil then
		profile:AddUserId(player.UserId) -- GDPR compliance
		profile:Reconcile() -- Fill in missing variables from ProfileTemplate (optional)
		profile:ListenToRelease(function()
			Profiles[player] = nil
			-- The profile could've been loaded on another Roblox server:
			if wipe then
				player:Kick("Data saved successfully :)")
			else
				player:Kick("Something went wrong loading data! Please rejoin :D")
			end
		end)
		if player:IsDescendantOf(game.Players) == true then
			Profiles[player] = profile
			
			if profile.Data.Banned then
				if profile.Data.BannedBy then
					player:Kick("You have been banned by "..profile.Data.BannedBy..".")
				else
					player:Kick("You have been banned.")
				end
			end

			folder.FirstName.Value =  profile.Data.FirstName
			folder.LastName.Value =  profile.Data.LastName
			. . .
			
		else
			-- Player left before the profile loaded:
			profile:Release()
			if player then
				player:Kick("Something went wrong loading data! Please rejoin :D #300") 
			end
		end
	else
		-- The profile couldn't be loaded possibly due to other
		--   Roblox servers trying to load this profile at the same time:
		player:Kick("Something went wrong loading data! Please rejoin :D #200") 
	end
end
game.Players.PlayerAdded:Connect(function(plr)
	-- creating folder
	PlayerAdded(plr,folder)
	-- connecting other events for gameplay
PlayerRemoving
local function DataSaveOnExit(plr)
	local profile = Profiles[plr]
	if profile ~= nil then
		if rs.PlayerData:FindFirstChild(plr.Name) then

			profile.Data.Money = rs.PlayerData[plr.Name].Money.Value
			. . .

		end
		profile:Release()
	end
end
game.Players.PlayerRemoving:Connect(function(plr)
	DataSaveOnExit(plr)
	-- removing folder
end)

Hi, I am slightly new to this module and just wanted to ask if using a module with a ton of public functions like GiveCash or GiveItem would be a good idea or if it would be better to handle data in their respective scripts.

I ran into a problem. After publishing the game, i tried 2 accounts to join a server. then I have 1 account rejoin the same server. the data of that account is lost in the same server.

when I have 2 account quit that server, and have lost data account join a different server, data is back again. does anyone know what bug is this

Edit: I fixed it was my code that make profile take infinite loop and never release

I honestly wouldn’t usually do this, but since this post keeps getting at the top of the page, why not?

For those who are perhaps looking for an alternative, maybe check out DocumentService.

ProfileService hasn’t been updated (or at least, seems like it) for a long while.

Just finished a quick ProfileService rewrite :eyes:
The project name is “ProfileStore” which represents the top class of this module.
Majority of changes involve code and comment cleanup, variable name cleanup, an upgrade to the GlobalUpdates feature and auto-complete support.

It will be backwards compatible with the original internal DataStore schema ProfileService has been using, but the method names will be different and “MetaTags” will be removed in favor of a new property “Profile.LastSavedData”.

There also exists a rewritten version of ReplicaService that’s slightly faster and also has cleaner method names.

If there’s enough interest from the community and motivation from my side I might make an open source release of these modules with full documentation :slight_smile:

45 Likes

Sounds neat…! Looking forward to using it if released!

2 Likes

Please just update the module because everyone just wants an update.

I’d take it even without the documentation

1 Like

please release the module we havent gotten an update in over 2 years i think :pray:

1 Like

bro it’s probably the most used datastore module ever made.

yes, the community is interested. let’s just uhhh skip on past that hype train and get to the part where you release it. pleaseee!!! :smiley:

2 Likes

+1 to the community interest for a release

1 Like

would be awesome to see an upgraded profileservice! interested to see what specific changes were made :eyes:

1 Like

Please add support for typechecking! :pray:

2 Likes

There’s one on GitHub made by another user iirc, just check the Github repo

just release it, people be craving for an update

how can i migrate my data to profile service? i’ve been using the traditional datastore and experiencing data loss

Definitely interested in the ReplicaService rewrite, even without documentation

ProfileStore

An updated module, successor to ProfileService, has been RELEASED:

2 Likes